gpt4 book ai didi

Java - 第一次使用构造函数 - 作业

转载 作者:行者123 更新时间:2023-12-02 06:33:50 30 4
gpt4 key购买 nike

在我的程序中,应该读取学生姓名、ID 号和 GPA,将其分配给指定的学生,然后打印出来。一切都编译正常,但出现错误 Error: Could not find or load main class Lab10.java。如有任何帮助,我们将不胜感激:)。

这是我的程序:

public class Lab10
{
private final static String NAME = "Glenn Coffey III";
private final static int STUID = 123456789;
private final static double GPA1 = 4.00;
private final static double GPA2 = 2.34;

public static void main(String[] args)
{
Student stu1;
stu1 = new Student(NAME, STUID, GPA1);
System.out.println("\nName: " + stu1.getName());
System.out.println("Id Number: " + stu1.getIdNum());
System.out.println("GPA: " + stu1.getGPA());
stu1.setGPA(GPA2);
System.out.println(stu1 + "\n");

Student stu2;
stu2 = new Student("Pistol Pete", 000000001, 4.00);
System.out.println("\nName: " + stu2.getName());
System.out.println("Id Number: " + stu2.getIdNum());
System.out.println("GPA: " + stu2.getGPA());
System.out.println(stu2 + "\n");
}
}

public class Student
{
private String name;
private int idNum;
private double gpa;
public Student(String namePar, int idNumPar, double gpaPar)
{
name = namePar;
idNum = idNumPar;
gpa = gpaPar;
}
public String getName()
{
return name;
}
public double getGPA()
{
return gpa;
}
public int getIdNum()
{
return idNum;
}
public void setStudentName(String n)
{
name = n;
}
public void setGPA(double d)
{
gpa = d;
}
public String toString()
{
String s = String.format("Name: %s, \nId Number: %d, \nGPA: %f, \nStudent name: %s, "
+ "\nStudent ID num: %d, \nStudent GPA: %f,", name, idNum, gpa, name, idNum, gpa);
return s;
}
}

最佳答案

听起来您可能发出了错误的终端命令。请尝试以下操作:

javac Lab10.java
java Lab10

关于Java - 第一次使用构造函数 - 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19850453/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com