Results 1 to 10 of 10
Thread: Second week into Java - errors
- 11-03-2010, 02:18 PM #1
Senior Member
- Join Date
- Oct 2010
- Posts
- 119
- Rep Power
- 0
Second week into Java - errors
Hey guys,
This is my second week into my Java How to Program college class, and honestly im feeling defeated. i have what should be a relatively simple task to reform, and i can't even get it to work. i have 2 java files i have to slightly modify to display different results, and initially got 10 errors, now its down to 4, but im stuck after spending 4 hows on something so basic, its frustrating. any help is appreciated, as i have a screenshot of the error, and the code if anyone is interested in helping.
- 11-03-2010, 02:58 PM #2
Kinda hard to help when you dont say what the problem is ^^ - please post the code and the errors.
Beginning a new language is always hard, we all make basic errors. Stick in there! :P
- 11-03-2010, 03:15 PM #3
- 11-03-2010, 03:36 PM #4
Senior Member
- Join Date
- Oct 2010
- Posts
- 119
- Rep Power
- 0
sorry my question was vague, i guess is was more a question to ask if anyone could help. Here is the error, and my code:
2 files:
Java Code:// fig 3.10 GradeBook.java // GradeBook class with a constructorto initialize the course Name public class GradeBook { private String courseName; // course name for this GradeBook private String instructorName; // instructor's name for this Gradebook // constructor initializes courseName and // instructor name with String argument public GradeBook ( String courseName, String instructorName) { setcourseName ( courseName) ; setinstructorName ( instructorName ); } // end constructor //method to set the course name public void setcourseName ( String name ) { courseName = name; // store the course name } // end method setCourseName // method to retrieve the course name public String getcourseName () { return courseName; } // end method getCourseName //method to set the instructor name public void setinstructorName ( String name ) { instructorName = name; // store the instructor name } // end method setInstructorName // method to retrieve the instructor name public String getinstructorName () { return instructorName; } // end method getIntructorName //display a welcome message to the GradeBook User public void displayMessage () { // this statement calls getCourseName to get the // name of the course this GradeBook represents System.out.printf ( "Welcome to the Grade Book for\n%s!\n", getcourseName ()); } // end method displayMessage }//end class GradeBook
SECOND FILE
Java Code:// fig 3.11 GradeBookTest.java // Gradebook constructor used to specify the course name at the // time each Gradebook object is created public class GradeBookTest { //main method begins program execution public static void main ( String [] args ) { // create GradeBook Object GradeBook gradeBook1 = new GradeBook( courseName , instructorName ); GradeBook gradeBook2 = new GradeBook( courseName , instructorName ); // display initial value of courseName for each Gradebook System.out.printf ( "gradeBook1 course name is: %s\n", gradeBook1.getcourseName() ); System.out.printf ( "gradeBook2 course name is: %s\n", gradeBook2.getcourseName() ); } // end main } // end class GradeBookTest
the error's im getting all refer to the GradeBookTest.java file, lines 12 and 14 "Cannot Find Symbol"
im down to 4 errors from 10, but in looking at it further, im thinking i have something messed up where its not going to output what im looking for either, but need to get the errors straight first.Last edited by hayden06f4i; 11-03-2010 at 03:44 PM. Reason: code tags
- 11-03-2010, 03:37 PM #5
Senior Member
- Join Date
- Oct 2010
- Posts
- 119
- Rep Power
- 0
there has to be a better way to show the code to you guys, keeping the indents....sorry about that mistake. how can i maintain the indents so its easier for you guys to read?
- 11-03-2010, 03:40 PM #6
Yeah, just use the code tags. You might have to click the "Go Advanced" button to see the button for it. It should look like this:
Also, code you post really should be in SSCCE form. And you should point out any line numbers mentioned in errors in your code, so we don't have to count. Call us lazy, but it's best to make it as easy as possible for people to help you.Java Code:System.out.println("So pretty!");
- 11-03-2010, 03:44 PM #7
In future, please could you use [code] and [/ code] (no space) tags around code you post... it makes it much easier to read.
Also, in future, when you get errors please post the full error messages. They are usually extremely useful, and by shortening them we cannot help you fully, or as quickly.
Luckily the code isnt too long so no harm this time :)
As to your problem.
The linepasses the variables 'courseName' and 'instructorName', however you have never said what these variables are (hence cannot find symbol)Java Code:GradeBook gradeBook1 = new GradeBook( courseName , instructorName );
I presume what you wanted to do is give the constructor actual values. You do this like this:
By wrapping text with quotations, you are telling the compiler they are string literals.Java Code:GradeBook gradeBook1 = new GradeBook( "An introduction to java" , "berkeleybross :P");
Another way of doing this is by defining the variables:
Please ask if this doesnt make sense.Java Code:String courseName = "An introduction to java"; String instructorName = "berkeleybross"; GradeBook gradeBook1 = new GradeBook(courseName , instructorName );
- 11-03-2010, 04:08 PM #8
Senior Member
- Join Date
- Oct 2010
- Posts
- 119
- Rep Power
- 0
that makes sense that i need to need to define what the variables are. absolutely, thank you!
so that raises the question now, what im trying to do is have the displayMessage modified to output a Welcome message and Course name, followed by "This course is presented by: " and the instructor.Last edited by hayden06f4i; 11-03-2010 at 04:53 PM.
- 11-03-2010, 04:56 PM #9
Senior Member
- Join Date
- Oct 2010
- Posts
- 119
- Rep Power
- 0
Sorry for the Double post, but......I GOT IT! thank you for your help....
after some more editing to what the strings display it shows:
gradebook1 course name is: CS101 Intro to Java Programming
This Course is presented by: Mr. Christian
gradebook2 course name is: CS102 Data Structures in java
This Course is presented by: Mr. Bellicheck
thanks guys. i hope to make it through some of my next question without help, but if not can i ask for more? haha.
- 11-03-2010, 05:01 PM #10
Similar Threads
-
Current dates in a week
By Isong in forum AWT / SwingReplies: 1Last Post: 11-02-2010, 05:08 AM -
Manipulate dates by week
By quiterin in forum Advanced JavaReplies: 1Last Post: 09-21-2009, 03:30 PM -
Day of the Week Calculator
By scheng12 in forum New To JavaReplies: 0Last Post: 09-08-2009, 03:59 PM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM -
Get dates of current week
By Qlubbie in forum New To JavaReplies: 2Last Post: 11-19-2008, 09:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks