Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2008, 05:57 AM
Member
 
Join Date: Feb 2008
Posts: 5
cart1443 is on a distinguished road
Why does it still have it as "Null"?
So why are the different instructor names showing up as "null" when the course name doesn't? They are formatted the same. Am I missing something?

PHP Code:
// Lab 2: GradeBook.java
// GradeBook class with a constructor to initialize the course name.

public class GradeBook
{
   private 
String courseName// course name for this GradeBook
   /* write code to declare a second String instance variable */
   
private String InstructorName;
   
   
// constructor initializes courseName with String supplied as argument
   
public GradeBookString name 
   {  
      
courseName name// initializes courseName 
   
// end constructor 

   // method to set the course name
   
public void setCourseNameString name )
   {
      
courseName name// store the course name
   
// end method setCourseName

   // method to retrieve the course name
   
public String getCourseName()
   {
      return 
courseName;
   } 
// end method getCourseName

   /* write code to declare a get and a set method for the instructor’s name */
   
public void setInstructorNameString Iname )
   {
      
InstructorName Iname// store the course name
   
// end method setCourseName

   // method to retrieve the course name
   
public String getInstructorName()
   {
      return 
InstructorName;
    }
   
    
// 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\n"
         
getCourseName() );
      
System.out.printf"This course is presented by: %s!\n"
         
getInstructorName() );
      
/* write code to output the instructor’s name */
   
// end method displayMessage

// end class GradeBook 
PHP Code:
// Lab 2: 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 mainString args[] )
   { 
      
// create GradeBook object
      
GradeBook gradeBook1 = new GradeBook("CS101 Introduction to Java Programming" );
      
GradeBook Iname1 = new GradeBook("Sam Smith");
      
GradeBook Iname2 = new GradeBook("Judy Jones");

      
gradeBook1.displayMessage(); // display welcome message
      
      /* write code to change instructor’s name and output changes */
      
      
Iname2.setInstructorName(Iname2.getInstructorName());
      
System.out.printf("\nChanging instructor name to %s"
            
Iname2.getInstructorName() );
   } 
// end main

// end class GradeBookTest 
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-07-2008, 07:56 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
The only way to set the name for the instructor is with the setInstructorName method which you did not use in your main method. Your only GradeBook constructor requires a String argument whose value is assigned to the "courseName" member variable. The member variable "InstructorName remains null until you assign it a value via the setInstructorName method.
Code:
public static void main( String args[] ) { GradeBook Iname1 = new GradeBook("Sam Smith"); Iname1.setInstructorName("John Stuart"); // Now it won't be null for the "Iname1" instance. ...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Name Coming Up As "null" sylo18 New To Java 8 10-31-2007 12:31 AM
Hwlp with "Open", "Save", "Save as..." trill New To Java 1 07-31-2007 09:53 AM
Exception in thread "main" java.net.ConnectException: Connection timed out osval Advanced Java 1 07-28-2007 12:59 AM
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException romina New To Java 1 07-26-2007 12:55 AM
ArrayList: Exception in thread "main" java.lang.NullPointerException susan New To Java 1 07-16-2007 08:32 AM


All times are GMT +3. The time now is 04:44 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org