I'm currently working on an assignment for my Java class with the following instructions:
Your application will consist of one class, PetAdvice.
Use an input dialog box to request the type of dwelling the program user lives in.
Edit the value entered into the input dialog box. The value must be A, a, H, h, D, or d. Display a message dialog box indicating an invalid value was entered if A, a, H, h, D, or d was not entered. Your message dialog must look like Figure 2 below. Stop the application after displaying the error message dialog if invalid data was entered. Continue processing if a valid value was entered.
The program logic to display the input dialog box and edit the input for type of dwelling must be in its own method and separate from main().
Use an input dialog box to request the number of hours the program user is at home during the day. Your input dialog must look like Figure 3 below.
Edit the value entered into the input dialog box. The value must be A, a, B, b, C, c, D, d, E or e. Display a message dialog box indicating an invalid value was entered if A, a, B, b, C, c, D, d, E or e was not entered. Your message dialog must look like Figure 4 below. Stop the application after displaying the error message dialog if invalid data was entered. Continue processing if a valid value was entered.
The program logic to display the input dialog box and edit the input for hours at home must be in its own method and separate from main().
Based on the type of dwelling and the number of hours at home, use this table to determine what type of pet the user should get. Display this recommendation in a message dialog box. Your message dialog box must look like Figure 5 below. Keep in mind the recommended pet will change based on the user input.
The program logic to determine the pet and display the message dialog box with the recommend pet must be in its own method and separate from main().
You may not use any "global" variables, that is variables declared outside a method.
You do not need to program a response when the user clicks the Cancel button or clicks the X in the upper right corner of the dialog. I will not test these features when I grade your application.
Based on the requirements above, you will have a minimum of four methods:
main( )
a method to process the type of dwelling
a method to process the number of hours at home
a method to determine and display the recommended pet.
I can't find what's wrong with my code that I am recieving the message "No main methods, applets, or MIDlets found in file."
import javax.swing.JOptionPane; public class PetAdvice { public void main(String[] args) { String Domicile; { Domicile = JOptionPane.showInputDialog(null, "Input A(Apartment), H(House), D(Dorm)"); switch(Domicile) { case "A": case "a": Domicile = "A"; break; case "H": case "h": Domicile = "H"; break; case "D": case "d": Domicile = "D"; break; default: { JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending"); System.exit(-1); } } } String Hours; { Hours = JOptionPane.showInputDialog(null, "Input A(18+ Hours), B(10-17 Hours), C(8-9 Hours), D(6-7 Hours), E(0-5 Hours)."); switch(Domicile) { case "A": case "a": Hours = "a"; break; case "B": case "b": Hours = "b"; break; case "C": case "c": Hours = "c"; break; case "D": case "d": Hours = "d"; break; case "E": case "e": Hours = "e"; break; default: { JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending"); System.exit(-1); } } } String petDetermination; { if (Domicile == "H") switch(Hours) { case "a": JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig."); break; case "b": JOptionPane.showMessageDialog(null, "You should get a Dog."); break; case "c": case "d": case "e": JOptionPane.showMessageDialog(null, "You should get a Snake."); break; } if (Domicile == "A") switch(Hours) { case "a": case "b": JOptionPane.showMessageDialog(null, "You should get a Cat."); break; case "c": case "d": case "e": JOptionPane.showMessageDialog(null, "You should get a Hamster."); break; } if (Domicile == "D") switch (Hours) { case "a": case "b": case "c": case "d": JOptionPane.showMessageDialog(null, "You should get a Fish."); break; case "e": JOptionPane.showMessageDialog(null, "You should get an Ant Farm."); break; } } } }