Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- class PetAdvice
- {
- public static void main(String args[]) throws Exception
- {
- int hours;
- int a = 0;
- char house = ' ';
- String hoursString;
- String petAdvice = "Hello";
- System.out.println("H) House");
- System.out.println("A) Apartment");
- System.out.println("D) Dormitory");
- System.out.println("Insert the word according to the type of residence you live in.");
- house = (char) System.in.read();
- while ((house != 'H') && (house != 'A') && (house != 'D'))
- {
- System.out.println("You didn't enter a correct house type insert H, A or D according to the residence.");
- house = (char) System.in.read();
- System.in.read();
- System.in.read();
- }
- hoursString = JOptionPane.showInputDialog("Insert number of hours you spend at your residence");
- hours = Integer.parseInt(hoursString);
- switch(house)
- {
- case('H'):
- {
- if(hours > 18)
- {
- a = 0;
- petAdvice = "Pot bellied pig";
- break;
- }
- if ((hours >= 10) && (hours <= 17))
- {
- a = 0;
- petAdvice = "Dog";
- break;
- }
- if ((hours < 10))
- {
- a = 0;
- petAdvice = "Snake";
- break;
- }
- }
- case('A'): {
- if (hours >= 10)
- {
- a = 0;
- petAdvice = "Cat";
- break;
- }
- if (hours < 10)
- {
- a = 0;
- petAdvice = "Hamster";
- break;
- }
- }
- case('D'):
- {
- if (hours >= 6)
- {
- petAdvice = "Fish";
- a = 0;
- break;
- }
- if (hours < 6)
- {
- petAdvice = "Ant farm";
- a = 0;
- break;
- }
- }
- default:
- {
- System.out.println("You didn't enter correct information.");
- a = 1;
- }
- }
- if (a != 1)
- {
- JOptionPane.showMessageDialog(null, "You should buy yourself a\n" + petAdvice, "Your pet advice", JOptionPane.INFORMATION_MESSAGE);
- }
- }
- }
Add Comment
Please, Sign In to add comment