a.Write an application that recommends a pet for a user based on the user\'s lif
ID: 3634041 • Letter: A
Question
a.Write an application that recommends a pet for a user based on the user's lifestyle. Prompt the user to enter whether he or she lives in an apartment, a house, or a dormitory (1, 2, or 3, respectively) and the number of hours the user is home during an average day. The user will select an hour category from a menu:1.18 or more
2.10 to 17
3.8 to 9
4.6 to 7
5.0 to 5
b.Output your recommendation based on the following table:
Residence Hours Home Recommendation
House 18 or more Pot-bellied pig
House 10 to 17 Dog
House fewer than 10 Snake
Apartment 10 or more cat
Apartment fewer than 10 hamster
Dormitory 6 or more fish
Dormitory fewer than 6 ant farm
Explanation / Answer
please rate - thanks
import java.util.*;
public class main
{public static void main(String [] args)
{Scanner in=new Scanner(System.in);
int n,i,hours,live;
System.out.println("Where do you live? 1)Apartment 2)house 3)dormitory");
live=in.nextInt();
System.out.println("How many hours are you home during the average day? 1)18 or more 2)10 to 17 3)8 to 9 4)6 to 7 5)0 to 5 ");
hours=in.nextInt();
System.out.print("Recommendation: ");
if(live==2)
if(hours==1)
System.out.println("Pot-bellied pig");
else if(hours==2)
System.out.println("Dog");
else
System.out.println("Snack");
else if(live==1)
if(hours<=2)
System.out.println("Cat");
else
System.out.println("Hamster");
else
if(hours<=4)
System.out.println("Fish");
else
System.out.println("Ant Farm");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.