package experiment_3; public class Student { //成员变量 private String sno;//学号 private int philosophy;//哲学课成绩 private int english;//英语课成绩 private int computer;//计算机课成绩 //构造方法 public Student() { super(); } public Student(String sno, int philosophy, int english, int computer) { super(); this.sno = sno; this.philosophy = philosophy; this.english = english; this.computer = computer; } //平均成绩 public int aver() { return (this.philosophy+this.english+this.computer)/3; } //最高分 public double max() { int m; if(this.philosophy>this.english) m=this.philosophy; else m=this.english; if(this.computer>m) m=this.computer; return m; } //最低分 public int min() { int n; if(this.philosophy>this.english) n=this.english; else n=this.philosophy; if(this.computer<n) n=this.computer; return n; } //用于获取学号、姓名、性别、平均分、最高分、最低分信息 //覆盖 public String getInfo() { System.out.println("学号:"+sno); super.show();//调用父类里边的成员方法 System.out.println("平均分:"+aver()); System.out.println("最高分:"+max()); System.out.println("最低分:"+min()); return null; } }为什么不能运行修改代码
时间: 2024-03-22 08:40:52 浏览: 42
这段代码不能运行是因为其中使用了一个没有定义的方法`super.show()`,而且`getInfo()`方法的返回值应该为String类型,而不是null。如果想要运行该代码,需要先定义一个父类,并在父类中定义`show()`方法。另外,建议将`getInfo()`方法的返回值改为String类型,并将`System.out.println()`改为字符串拼接的形式,以便更好地输出信息。
相关问题
class Person{ private String name; private int age; private char gender; public Person(String name,int age,char gender){ this.name=name; this.age=age; this.gender=gender; } public void printInfo(){ System.out.println("姓名: "+name); System.out.println("年龄: "+age); System.out.println("性别: "+gender); } } class Student extends Person{ private String school; private int score; public Student(String name,int age,char gender,String school,int score){ super(name,age,gender); this.school=school; this.score=score; } public void printInfo(){ super.printInfo(); System.out.println("学校: "+school); System.out.println("成绩: "+score); } } class Teacher extends Person{ private String course; public Teacher(String name,int age,char gender,String course){ super(name,age,gender); this.course=course; } public void printInfo(){ super.printInfo(); System.out.println("课程: "+course); } } //替换下面的学生信息,修改主类的名字 public class Experiment_04_01 { public static void main(String[] args) { Student stud=new Student01("lili",19,'F',"齐鲁工业大学",90); Teacher tech=new Teacher("coco",30,'F',"高级程序设计"); stud.printInfo(); System.out.println(); tech.printInfo(); } }
抱歉,您的代码有一些错误。首先,您在创建学生对象时使用了错误的类名,应该是"Student"而不是"Student01"。其次,由于您的代码中没有定义名为"Student01"的类,因此需要将主类的名字从"Experiment_04_01"修改为"Main"。以下是修改后的代码:
```java
class Person {
private String name;
private int age;
private char gender;
public Person(String name, int age, char gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public void printInfo() {
System.out.println("姓名: " + name);
System.out.println("年龄: " + age);
System.out.println("性别: " + gender);
}
}
class Student extends Person {
private String school;
private int score;
public Student(String name, int age, char gender, String school, int score) {
super(name, age, gender);
this.school = school;
this.score = score;
}
public void printInfo() {
super.printInfo();
System.out.println("学校: " + school);
System.out.println("成绩: " + score);
}
}
class Teacher extends Person {
private String course;
public Teacher(String name, int age, char gender, String course) {
super(name, age, gender);
this.course = course;
}
public void printInfo() {
super.printInfo();
System.out.println("课程: " + course);
}
}
public class Main {
public static void main(String[] args) {
Student stud = new Student("lili", 19, 'F', "齐鲁工业大学", 90);
Teacher tech = new Teacher("coco", 30, 'F', "高级程序设计");
stud.printInfo();
System.out.println();
tech.printInfo();
}
}
```
请注意,我已经将主类名更改为"Main",并将学生对象的类名更正为"Student"。现在您可以运行该代码并得到预期的输出。
"randga": { "test_dataset_path": "../data/cave/randga25/test.npz", "scene_id": 0, "result_dir": "results/cave/randga25", "model_path": "saved_models/icvl/randga55/pretrained/experiment_0/models/epoch_92", }, }
这段代码是什么意思?
这段代码是一个 JSON 格式的配置文件,其中包含了一个名为 "randga" 的场景的配置信息,包括:
- "test_dataset_path":该场景的测试数据集路径;
- "scene_id":该场景的 ID;
- "result_dir":结果保存的目录;
- "model_path":使用的模型路径。
阅读全文