Java的一个关于类的基础程序.Modify class GradeBook (Fig.3.10) as follows:a) Include a String instance variable that represents the name of the course’s instructor.b) Provide a set method to change the instructor’s name and a get method

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 03:10:38
Java的一个关于类的基础程序.Modify class GradeBook (Fig.3.10) as follows:a) Include a String instance variable that represents the name of the course’s instructor.b) Provide a set method to change the instructor’s name and a get method

Java的一个关于类的基础程序.Modify class GradeBook (Fig.3.10) as follows:a) Include a String instance variable that represents the name of the course’s instructor.b) Provide a set method to change the instructor’s name and a get method
Java的一个关于类的基础程序.
Modify class GradeBook (Fig.3.10) as follows:
a) Include a String instance variable that represents the name of the course’s instructor.
b) Provide a set method to change the instructor’s name and a get method to retrieve it.
c) Modify the constructor to specify two parameters—one for the course name and one
for the instructor’s name.
d) Modify method displayMessage to output the welcome message and course name,fol-
lowed by "This course is presented by:" and the instructor’s name.
Use your modified class in a test application that demonstrates the class’s new capabilities.
Fig.3.10中的程序:
public class GradeBook
{
private String courseName;
}
public GradeBook( String name )
{
courseName = name;
}
public void setCourseName( String name )
{
courseName = name;
}
public String getCourseName()
{
return courseName;
}
public void displayMessage()
{ System.out.printf( "Welcome to the grade book for\n%s!\n",
getCourseName() );
}
}
.我一开始先把如上的程序打上去,但都运行不了.然后就无力了.

Java的一个关于类的基础程序.Modify class GradeBook (Fig.3.10) as follows:a) Include a String instance variable that represents the name of the course’s instructor.b) Provide a set method to change the instructor’s name and a get method
第三行多了个花括号吧 而且没有main()方法
改成这样应该是你要的结果
public class Console{
private String courseName;
public Console( String name ){
courseName = name;
}
public void setCourseName( String name ){
courseName = name;
}
public String getCourseName(){
return courseName;
}
public void displayMessage(){
System.out.printf( "Welcome to the grade book for\n%s!\n",getCourseName() );
}
public static void main(String[] args){
new Console("网友").displayMessage();
}
}

下列关于Java Application程序在结构上特点的描述中,错误的是( ).下列关于Java Application程序在结构上特点的描述中,错误的是( ).AJava程序是由一个或多个类组成的 B组成Java程序的若干个 Java的一个关于类的基础程序.Modify class GradeBook (Fig.3.10) as follows:a) Include a String instance variable that represents the name of the course’s instructor.b) Provide a set method to change the instructor’s name and a get method 三个数从小到大排序的JAVA程序 怎么编写“从3个数中选最大的数”java程序谢谢了,编写一个java程序,实现从3个数中选最大的. java程序中如何产生随机数(一个按钮产生一个1~100的随机数) 求程序~ 用JAVA写一个程序,求N个不同形状的图形的总面积. 如何编写一个打印50~100随机数的简单的程序用java写 用java编写一个输出1到00以内的素数并求和的程序 编写一个程序 ,采用方法重载分别实现圆、三角形、矩形、椭圆的面积计算 是用java程序哦 JAVA 程序练习程序填空,不要改变与输入输出有关的语句.输入一个正整数repeat (0 1、编写一个Java程序,计算并输出1+2!+3!+…+10!的值. 编写一个JAVA程序,求1!+2!+3!+.+10!的结果,并将结果输出 设计一个java程序,从键盘输入三个整数,按照从小到大的顺序输出 使用java程序接收一个小于10的整数n,计算并输出阶乘. JAVA练习题,程序填空,不要改变与输入输出有关的语句.输入一个正整数repeat (0 用Java编写一个程序可以打印如下三角形一定要有详细的说明才行! 在java中,下面选项中关于java.lang.Object 类的说法错误的是( )在java中,下面选项中关于java.lang.Object 类的说法错误的是( )A、在java中,所有的JAVA类都直接继承了Object 类B、假定在定义一个类时,没有 帮忙编写一个java程序(很基础的那种).Write a program which accepts a time interval in seconds and prints the equivalent time in hours minutes seconds.One hour is 3600 seconds and one minute is 60 seconds.