gpt4 book ai didi

java - 我应该在哪里声明此代码中的字段才能编译?

转载 作者:行者123 更新时间:2023-12-01 15:38:26 26 4
gpt4 key购买 nike

这不应该是一个客户端类。我只是做一个类(class)供其他人使用。我将其用于高中。例如,我有地址老师学生校长房间号的类(class)> 等。但由于某些奇怪的原因它没有编译。我相信这是因为我没有声明一个字段但不确定。

import java.io.*;


public class HighSchool {
// Constructors
public HighSchool() { }

public HighSchool(String title, String teacher, int roomNumber, String period, String[] students, String address, String subjects ) {
this.title = title;
this.teacher = teacher;
this.roomNumber = roomNumber;
this.period = period;
this.String[] students = students;
this.String address =a ddress;
this.String subjects = subjects;
}
public class Classcourse (String title, String teacher, int roomNumber, String period, String[] students, String address, String subjects

private String period;) {

public String gettitle() {
return title;
}
public void settitle(String title) {
this.title = title;
}
public String getteacher() {
return teacher;
}
public void setteacher(String teacher) {
this.teacher = teacher;
}
public int getroomNumber() {
return roomNumber;
}
public void setroomNumber (int roomNumber) {
this.roomNumber = roomNumber;
}
public String getperiod() {
return getperiod();
}
public void setperiod (String period) {
this.period = period;
}
public String[] getstudents () {
return students[];
}
public void setstudents[] (String[] students

private String address;) {
this.students = students;
}
public String getaddress() {
return address;
}
public void setaddress (String address) {
this.address = address;
}
public String getsubjects() {
return subjects;
}
public void setsubjects (String subjects) {
this.subjects = subjects;
}
}


// modifier method
public void addstudents(String students) {
String[] newstudents = new String[students.length + 1];
for (int i = 0; i < students.length; i++) {
newstudents[i] = students[i];
}
newstudents[students.length] = student;
students = newstudents;
}

public boolean isInClass(String students) {
for (int i = 0; i < students.length; i++) {
if (students[i].equals(students)) {
return true;
}
}


return false;
}

// static creator method
public static HighSchool readFromInput() throws IOException {
BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a HighSchool title: ");
HighSchool newHighSchool = new HighSchool(kb.readLine());
String students = null;
do {
System.out.print("Enter a student, or press Enter to finish: ");
students = kb.readLine();
if (students != null){
newHighSchool.addstudents(students);
}
} while (students != null);
return newHighSchool;
}


// Variables (Fields)
private String title;
private String[] students;
}

最佳答案

此外,你写的东西从Java编译器的角度来看是没有意义的:

私有(private)字符串句点;) { - 可能删除“)”。

第二件事:

看一下 Classcourse 类的声明。这听起来相当错误,尽管这可能是该网站编辑器的问题或其他问题......

一个“总体”提示 - java 有一个非常“智能”的编译器,在大多数情况下它可以准确地指出您的代码出了什么问题,因此,假设您是 Java 新手,请尝试了解编译器所说的内容给你。

祝你好运!

关于java - 我应该在哪里声明此代码中的字段才能编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8485117/

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