Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In addition to what I have so far, I need to ? Use the Scanner class to prompt t

ID: 3651198 • Letter: I

Question

In addition to what I have so far, I need to ? Use the Scanner class to prompt the user for their choices. ? Use a switch statement to determine the type of residence. ? Use if...else statements to determine the recommended pet. ? If the user enters an invalid residence choice, display an error message. import java.util.Scanner; public class PetAdvice { public static void main(String[] args) { int houseType; int hoursHome; Scanner input=new Scanner(System.in); System.out.println("Type of living 1.Apartment 2.House 3.Dormitory"); System.out.println("Enter residence choice:"); houseType=input.nextInt(); System.out.println("Categories 1. 18 or more 2. 10 to 17 3. 8 to 9 4. 6 to 7 5. 0 to 5."); System.out.println("Hours spend at home:"); hoursHome=input.nextInt(); if(hoursHome ==1) { if(houseType==2) System.out.println("Pet recommended is Pot-bellied pig"); } else if(hoursHome==2) { if(houseType==2) System.out.println("Pet recommended is Dog"); else if(houseType==1) System.out.println("Pet recmmoneded is Cat"); } else if(hoursHome==3 || hoursHome ==4) { if(houseType==2) System.out.println("Pet recommended is Snake"); else if(houseType==1) System.out.println("Pet recommended is Hamster"); else { System.out.println("Pet recommended is Firsh"); } } else if(hoursHome==5) { if(houseType==3) System.out.println("Pet recommended is Ant Farm"); } } }

Explanation / Answer

import java.util.Scanner;
public class PetAdvice
{
    public static void main(String[] args)
    {
        int houseType;
        int hoursHome;
        Scanner input=new Scanner(System.in);
        System.out.println("Type of living 1.Apartment 2.House 3.Dormitory");
        System.out.print("Enter residence choice:");
        houseType=input.nextInt();
        System.out.println("Categories 1. 18 or more 2. 10 to 17 3. 8 to 9 4. 6 to 7 5. 0 to 5.");
        System.out.print("Hours spend at home:");
        hoursHome=input.nextInt();
        if(hoursHome ==1)
        {
            if(houseType==2) System.out.println("Pet recommended is Pot-bellied pig");
        }
        else if(hoursHome==2)
        {
            if(houseType==2) System.out.println("Pet recommended is Dog");
            else if(houseType==1) System.out.println("Pet recmmoneded is Cat");
        }
        else if(hoursHome==3 || hoursHome ==4)
        {
            if(houseType==2) System.out.println("Pet recommended is Snake");
            else if(houseType==1) System.out.println("Pet recommended is Hamster");
            else
            {
                System.out.println("Pet recommended is Firsh");
            }
        }
        else if(hoursHome==5)
        {
            if(houseType==3) System.out.println("Pet recommended is Ant Farm");
        }
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote