-
Newbie Help
Hey guys can anyone figure out why this will not compile. It is a test file for a class I wrote that seems ok. I am very new to java and hope it is something easy. Thanks
public class Examone
{
public static void main(String[] args)
{
String input;
Madlib myMadlib = new Madlib();
{
input = JOptionPane.showInputDialog("Please enter a adjective ");
myMadlib.setAdj1(input);
input = JOptionPane.showInputDialog("Please enter a First name ");
myMadlib.setFirst(input);
input = JOptionPane.showInputDialog("Please enter a illness ");
myMadlib.setIllness(input);
input = JOptionPane.showInputDialog("Please enter a plural noun ");
myMadlib.setNoun1(input);
input = JOptionPane.showInputDialog("Please enter a adjective ");
myMadlib.setAdj2(input);
input = JOptionPane.showInputDialog("Please enter a number ");
myMadlib.setCookies(input);
input = JOptionPane.showInputDialog("Please enter a adjective ");
myMadlib.setAdj3(input);
input = JOptionPane.showInputDialog("Please enter a noun ");
myMadlib.setNoun2(input);
input = JOptionPane.showInputDialog("Please enter a place ");
myMadlib.setPlace(input);
input = JOptionPane.showInputDialog("Please enter a number ");
myMadlib.setDegree(input);
input = JOptionPane.showInputDialog("Please enter a job occupation ");
myMadlib.setJob(input);
}
JOptionPane.showMessageDialog(null, + myMadlib.setAdj1() + "will not be attending school online today. He/she has come down with a case of" + myMadlib.setFirst() + "and" + myMadlib.setIllness() + "has a horrible" + myMadlib.setNoun1() + "and a/an" + myMadlib.setAdj2() + "fever. He/She has tossed their cookies" + myMadlib.setCookies() + " times.");
JOptionPane.showMessageDialog(null, "We have made an appointment with the" + myMadlib.setAdj3() + "Dr." + myMadlib.setNoun2() + " who studied for many years in" + myMadlib.setPlace() + "and has" + myMadlib.setDegree() + "degrees in" + myMadlib.setJob(). "He will send you all the information you need. Thank You!");
JOptionPane.showMessageDialog(null, "Sincerely, Your favorite student");
System.exit(0);
}
}
}
-
what is the error you are getting?
-
Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
3 errors
c:\java>javac Examone.java
Examone.java:56: <identifier> expected
JOptionPane.showMessageDialog(null, "We have made an appointment with
the" + myMadlib.setAdj3() + "Dr." + myMadlib.setNoun2() + " who studied for man
y years in" + myMadlib.setPlace() + "and has" + myMadlib.setDegree() + "degrees
in" + myMadlib.setJob(). "He will send you all the information you need. Thank Y
ou!");
^
Examone.java:56: ';' expected
JOptionPane.showMessageDialog(null, "We have made an appointment with
the" + myMadlib.setAdj3() + "Dr." + myMadlib.setNoun2() + " who studied for man
y years in" + myMadlib.setPlace() + "and has" + myMadlib.setDegree() + "degrees
in" + myMadlib.setJob(). "He will send you all the information you need. Thank Y
ou!");
^
Examone.java:63: class, interface, or enum expected
}
^
3 errors
c:\java>
-
-
Quote:
Originally Posted by
mattkid
Is my code that bad?
Yes sorry to say, but it is. You are breaking one of the cardinal rules of coding: you are trying to add good code to bad, and this means that your entire process of coding is wrong.
I'd scrap this code and start over, and this time only add good code to good. By this, I mean to only add a small amount of code at a time, compile the program after adding this small amount of code, and immediately fix any errors you find then and there. Do not try to add any more code until the current program compiles (and if possible, runs) error free. If you don't do this you'll end up with what you have now: a holy mess.
A few other suggestions: Make sure you're importing your JOptionPane class, and make sure that you're not calling setXXXX methods when you should be calling getXXX methods.