Results 1 to 6 of 6
  1. #1
    subiedude101 is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default Errors in my third Java assignment

    This is my third Java assignment for my class and i'm already having lots of trouble..It's kind of frustrating, especially since I know I have a loong way to go and this should be pretty basic. I guess patience is a virtue though:o

    I have two java files that have to be slightly modified. What they want is this...

    1) Include a String instance variable that represents the name of the course's instructor

    2) Provide a set method to change the instructor's name and a get method to retrieve it.

    3) Modify the constructor to specify two parameters--one for the course name and one for the instructor's name.

    4) Modify method displayMessage to output the welcome message and course name, followed by "This course is presented by:" and the instructors name.

    Here is what I have so far---(first file--Gradebook)

    I included the lines where it says I have errors.

    Java Code:
    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)
    	{
    **ln13**		courseName = name;
    **ln14**		instructorName = name;
    	} // 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 )
    	{
    **ln32**		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
    and the second file--(GradeBookTest)
    Java Code:
    public class GradeBookTest
    {
    	//main method begins program execution
    	public static void main ( String [] args )
    	{
    		// create GradeBook Object
    		GradeBook gradeBook1 = new GradeBook(
    			"CS101 Introduction to Java Programming" , "Hank Hill" );
    		GradeBook gradeBook2 = new GradeBook(
    			"CS102 Data Structures in Java", "Dale Gribble" );
    			
    		// display initial value of courseName for each Gradebook
    		System.out.printf( "gradeBook1 course name is: %s\n",
    **ln18**			gradeBook1.getCourseName() );
    		System.out.printf( "gradeBook2 course name is: %s\n",
    **ln20**			gradeBook2.getCourseName() );
    		
    		System.out.printf( "This course is presented by: %s\n",
    **ln23**			gradebook1.getInstructorName() );
    		System.out.printf( "This course is presented by: %s\n",
    **ln25** 		        gradebook2.getInstructorName() );
    
    	} // end main
    } // end class GradeBookTest

    This what the errors say when I run it in the command prompt.


    Java Code:
    C:\Examples\ch03\fig03_10_11>javac *.java
    GradeBook.java:13: cannot find symbol
    symbol  : variable name
    location: class GradeBook
                    courseName = name;
                                 ^
    GradeBook.java:14: cannot find symbol
    symbol  : variable name
    location: class GradeBook
                    instructorName = name;
                                     ^
    GradeBook.java:32: cannot find symbol
    symbol  : variable InstructorName
    location: class GradeBook
                    InstructorName = name; // store the instructor name
                    ^
    GradeBookTest.java:18: cannot find symbol
    symbol  : method getCourseName()
    location: class GradeBook
                            gradeBook1.getCourseName() );
                                      ^
    GradeBookTest.java:20: cannot find symbol
    symbol  : method getCourseName()
    location: class GradeBook
                            gradeBook2.getCourseName() );
                                      ^
    GradeBookTest.java:23: cannot find symbol
    symbol  : variable gradebook1
    location: class GradeBookTest
                            gradebook1.getInstructorName() );
                            ^
    GradeBookTest.java:25: cannot find symbol
    symbol  : variable gradebook2
    location: class GradeBookTest
                            gradebook2.getInstructorName() );
                            ^
    7 errors

    If someone could push me in the right direction, that would be much appreciated.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Here:

    Java Code:
    	public GradeBook ( String courseName, String instructorName)
    	{
    **ln13**		courseName = name;
    **ln14**		instructorName = name;
    	}
    There is no variable or parameter called "name" and so the compiler complains. You need to use the variable and parameter names that are present rather than make them up. For instance for the first line, you'd do:

    Java Code:
    	public GradeBook ( String courseName, String instructorName)
    	{
    		this.courseName = courseName;
    		//...
    	}
    Where the this.courseName on the left of the assignment stands for the field of the class, and the courseName on the right of the assignment represents the parameter passed into the method. You want to set the guy on the left with the value passed into the guy on the right.

  3. #3
    subiedude101 is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default

    OK- I made the following changes, but i'm still having issues. Am I not declaring my variables correctly or what?

    Java Code:
    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 name, String instructor)
    	{
    		courseName = name;
    		instructorName = instructor;
    	} // 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 instructor )
    	{
    		InstructorName = Instructor; // 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:
    public class GradeBookTest
    {
    	//main method begins program execution
    	public static void main ( String [] args )
    	{
    		// create GradeBook Object
    		GradeBook gradeBook1 = new GradeBook(
    			"CS101 Introduction to Java Programming" , "Hank Hill" );
    		GradeBook gradeBook2 = new GradeBook(
    			"CS102 Data Structures in Java", "Dale Gribble" );
    			
    		// 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() );
    		
    		System.out.printf( "This course is presented by: %s\n",
    			gradebook1.getinstructorName() );
    		System.out.printf( "This course is presented by: %s\n",
    			gradebook2.getInstructorName() );
    
    	} // end main
    } // end class GradeBookTest
    Error report---
    Java Code:
    C:\Examples\ch03\fig03_10_11>javac *.java
    GradeBook.java:32: cannot find symbol
    symbol  : variable InstructorName
    location: class GradeBook
                    InstructorName = Instructor; // store the instructor name
                    ^
    GradeBook.java:32: cannot find symbol
    symbol  : variable Instructor
    location: class GradeBook
                    InstructorName = Instructor; // store the instructor name
                                     ^
    GradeBookTest.java:18: cannot find symbol
    symbol  : method getCourseName()
    location: class GradeBook
                            gradeBook1.getCourseName() );
                                      ^
    GradeBookTest.java:20: cannot find symbol
    symbol  : method getCourseName()
    location: class GradeBook
                            gradeBook2.getCourseName() );
                                      ^
    GradeBookTest.java:23: cannot find symbol
    symbol  : variable gradebook1
    location: class GradeBookTest
                            gradebook1.getinstructorName() );
                            ^
    GradeBookTest.java:25: cannot find symbol
    symbol  : variable gradebook2
    location: class GradeBookTest
                            gradebook2.getInstructorName() );
                            ^
    6 errors

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Java Code:
    GradeBook.java:32: cannot find symbol
    symbol  : variable InstructorName
    location: class GradeBook
                    InstructorName = Instructor; // store the instructor name

    Follow Java naming conventions and start variables (and methods) with a lowercase letter. In part this will solve problems like this one.

    Another convention is to use camelCase when you have variables and methods made up of multiple words like getCourseName(). You have a choice with something like "gradebook": but make that choice and then stick to it. The compiler will complain about the smallest typo so you have to be absolutely consistent in how you spell things.

  5. #5
    subiedude101 is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default

    Awesome, I got it working. Thank you so much guys. What a good feeling this is:D

    I think I found a new favorite forum, lol;)

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

Similar Threads

  1. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  2. Help me please (Java assignment)
    By cris_carriaga in forum Java Applets
    Replies: 4
    Last Post: 10-06-2010, 05:11 PM
  3. Java assignment
    By xtianah77 in forum New To Java
    Replies: 1
    Last Post: 02-18-2008, 12:54 AM
  4. java assignment, need help bad.
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 05:53 PM
  5. Help with my assignment java
    By toby in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:59 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
  •