importjava.util.*; importjavax.swing.*; importjava.lang.*; publicclass PetAdvice
ID: 3610515 • Letter: I
Question
importjava.util.*;
importjavax.swing.*;
importjava.lang.*;
publicclass PetAdvice
{
publicstatic void main(String []args)
{
String response = JOptionPane.showInputDialog(null, "Doyou live in an apartment,house, or dormitory? Type A-apartment, H-house, or D-dormitory. ");
String work = JOptionPane.showInputDialog(null, "How many hours are you home during the average day? A)18or more; B)10 to 17; C)8 to 9; D)6 to &; or E)0 to 5;");
charc = response.charAt(0);
switch(c)
{
case'H':
case'h':
{
if(A >= 18 || a >=a)
JOptionPane.showMessageDialog(null,"Recommendation: Pot bellied pig ");
else if(B >= 10 &&B <= 17 || b >= 10 && b <= 17)
JOptionPane.showMessageDialog(null,"Recommendation: Dog ");
elseif(C <= 10 || c <= 10)
JOptionPane.showMessageDialog(null,"Recommendation: Snake ");
break;
}
case'A':
case'a':
{
if(B >= 10 || b>=10)
JOptionPane.showMessageDialog(null,"Recommendation: Cat ");
else if(C< 10 || c <10)
JOptionPane.showMessageDialog(null,"Recommendation: Hamster ");
break;
}
case'D':
case'd':
{
if(D >= 6 || d >=6)
JOptionPane.showMessageDialog(null,"Recommendation: Fish ");
else if(E < 6 || e <6)
JOptionPane.showMessageDialog(null,"Recommendation: Ant farm ");
}
}
}
}
Explanation / Answer
please rate - thanks try this import java.util.*; import javax.swing.*; import java.lang.*; public class PetAdvice { public static void main(String []args) { String response = JOptionPane.showInputDialog(null, "Do you live inan apartment,house, or dormitory? Type A-apartment, H- house, orD-dormitory. "); String work = JOptionPane.showInputDialog(null, "How many hours areyou home during the average day? A)18 or more; B)10 to 17; C)8 to9; D)6 to &; or E)0 to 5; "); char c = response.charAt(0); char hours=work.charAt(0); switch (c) { case 'H': case 'h': { if(hours=='A' || hours=='a') JOptionPane.showMessageDialog(null,"Recommendation: Pot bellied pig"); else if(hours== 'B' ||hours=='b') JOptionPane.showMessageDialog(null,"Recommendation: Dog "); else JOptionPane.showMessageDialog(null,"Recommendation: Snake"); break; } case 'A': case 'a': { if(hours=='A' ||hours=='a'||hours=='B'||hours=='b') JOptionPane.showMessageDialog(null,"Recommendation: Cat "); else JOptionPane.showMessageDialog(null,"Recommendation: Hamster "); break; } case 'D': case 'd': { if(hours=='E' ||hours=='e') JOptionPane.showMessageDialog(null,"Recommendation: Ant farm"); else JOptionPane.showMessageDialog(null,"Recommendation: Fish "); } } } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.