初学者关于java类的一个问题
来源:百度知道 编辑:UC知道 时间:2024/05/21 08:04:40
要求做一个StudentDate程序,要求可以输出入学生姓名和成绩。要用到Student和StudentData2两个类。
Student类包括一个构造方法和一个称作GetResult的方法,通过构造方法初始化Student类的姓名和成绩两个私有属性,Student类的构造方法用来对Student类 两个属性设置值,Student类包含GetResult()方法,该方法用来计算Student类的对象成绩是不是及格并显示。
StudentDate2 类包括一个main方法,在该方法中创建2个Student类型的对象,并恩别调用GetResult
题目就是这样,可是我只会写这部分,类那些不知道往那里写
import java.io.*;
public class StudentData
{
public static void main(String args[])
{
double Score;
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入姓名:");
String inputLine=in.readLine();
System.out.print("请输入成绩:");
inputLine=in.readLine();
Score=Double.valueOf(inputLine).doubleValue();
}
catch(Exception e)
{
System.out.println("
import java.util.*;
public class StudentDate2{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("请输入学生1的姓名:");
String stuName1=input.nextLine();
System.out.print("请输入学生2的姓名:");
String stuName2=input.nextLine();
System.out.print("请输入学生1的成绩:");
float score1=input.nextLine();
System.out.print("请输入学生2的成绩:");
float score2=input.nextLine();
Student stu1 = new Student(stuName1,score1);
stu1.getResult();
Student stu2 = new Student(stuName2,score2);
stu2.getResult();
}
}
class Student{
private String stuName;
private float score;
public Student(String stuName,float score){
this.stuName = stuName;
this.score = sco