Results 1 to 10 of 10
  1. #1
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Unhappy 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.

  2. #2
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    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

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

  4. #4
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    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

  5. #5
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    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?

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    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:

    Java Code:
    System.out.println("So pretty!");
    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.

  7. #7
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    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 line
    Java Code:
    GradeBook gradeBook1 = new GradeBook(
    courseName , instructorName );
    passes the variables 'courseName' and 'instructorName', however you have never said what these variables are (hence cannot find symbol)

    I presume what you wanted to do is give the constructor actual values. You do this like this:
    Java Code:
    GradeBook gradeBook1 = new GradeBook(
    "An introduction to java" , "berkeleybross :P");
    By wrapping text with quotations, you are telling the compiler they are string literals.

    Another way of doing this is by defining the variables:
    Java Code:
    String courseName = "An introduction to java";
    String instructorName = "berkeleybross";
    GradeBook gradeBook1 = new GradeBook(courseName , instructorName );
    Please ask if this doesnt make sense.

  8. #8
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    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.

  9. #9
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    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.

  10. #10
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Glad to be of help!
    And yes, feel free to ask. Just start a new thread when you need to :)

Similar Threads

  1. Current dates in a week
    By Isong in forum AWT / Swing
    Replies: 1
    Last Post: 11-02-2010, 05:08 AM
  2. Manipulate dates by week
    By quiterin in forum Advanced Java
    Replies: 1
    Last Post: 09-21-2009, 03:30 PM
  3. Day of the Week Calculator
    By scheng12 in forum New To Java
    Replies: 0
    Last Post: 09-08-2009, 03:59 PM
  4. Replies: 3
    Last Post: 03-08-2009, 01:51 AM
  5. Get dates of current week
    By Qlubbie in forum New To Java
    Replies: 2
    Last Post: 11-19-2008, 09:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •