عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 01-03-2012, 08:25 PM   #97

sodelicious

سترك يارب

الصورة الرمزية sodelicious

 
تاريخ التسجيل: Feb 2010
التخصص: مؤجل حتى نهاية الترم
نوع الدراسة: إنتظام
المستوى: الرابع
الجنس: أنثى
المشاركات: 147
افتراضي رد: }{ تعالو نفهم بعض الsheet }{....برمجة 2

ياجماعة في احد حل سؤال اللاب التاني؟؟
Modify class GradeBook (Fig. L 3.3). Include a second String instance variable that represents the name of the course’s instructor. Provide a set method to change the instructor’s name and a get method to retrieve it. Modify the constructor to specify two parameters—one for the course name and one for the instructor’s name. Modify method displayMessage such that it first outputs the welcome message and course name, then outputs "This course is presented by: " followed by the instructor’s name. Modify the test application (Fig. L 3.4) to demonstrate the class’s new capabilities.
كود:
package lab2;

// 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 GradeBook( String name )
{
courseName = name; // initializes courseName
} // 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

public void get(String name)
{
	instructorName= name;
}

// 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() );
/* write code to output the instructor’s name */

} // end method displayMessage

} // end class GradeBook

package lab2;

//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 main( String args[] )
{
//create GradeBook object
GradeBook gradeBook1 = new GradeBook(
"CS101 Introduction to Java Programming" );

gradeBook1.displayMessage(); // display welcome message

/* write code to change instructor’s name and output changes */



} // end main

} // end class GradeBookTest

 

sodelicious غير متواجد حالياً   رد مع اقتباس