Write, so I have very little programming experience, and so I'm trying to wrap my head around my Java class, I'm working at it, but I'm struggling on some points. Basically I try to follow the assignment instructions given by my programming professor but like any program, a bit of it is open to interpretation. My latest assignment is as follows....
[highlight-instruction]
The purpose of this assignment is to create and use dialog boxes and selection statements. It is based on a problem from Java Programming by Joyce Farrell. This application will recommend a pet to the user based on the type of dwelling the user lives in and the number of hours per day the user is at home.
Your application will consist of one class, PetAdvice.
Use an input dialog box to request the type of dwelling the program user lives in. Your input dialog must look like Figure 1 below.
Figure 1
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.
Figure 2
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.
Figure 3
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.
Figure 4
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.
Figure 5
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.
This project is worth a maximum of 40 points. Check the class syllabus for the penalties for submitting an assignment late.
[/highlight]
I've gotten some code written for it, but I'm at a loss as to what I'm supposed to fill my main() method with. I've got no errors in the code that I've written thus far, but when I compile and run it does absolutely nothing, it's like it's going through the motions but never getting anywhere. The code I have is as follows:
I imagine the code could look a little neater or better, but it's what I've got so far with my very limited skills. I did take a C++ class about 9 years ago, and didn't do very well then either, but I also wasn't in the mind set of actually trying, older and wiser now, and I really want to understand this what I'm doing wrong, and get into that programmer mindset. Programming isn't my major, but it's still something that interests me.import javax.swing.JOptionPane; public class PetAdvice { String Domicile; String Hours; public static void main(String[] args) { } public void 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); } } } public void 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); } } } public void 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; } } }
Edit:
Also tried to use the spoiler tags as you can see, guess they don't work >.< or they're incorrect, is there a different code I should use?