Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我应该在哪里声明此代码中的字段,以便对其进行编译?_Java_Variables_Declaration - Fatal编程技术网

Java 我应该在哪里声明此代码中的字段,以便对其进行编译?

Java 我应该在哪里声明此代码中的字段,以便对其进行编译?,java,variables,declaration,Java,Variables,Declaration,这不应该是客户机类。我只是在给别人上课。我在一所高中用这个。例如,我为地址,老师,学生,校长,房间号,等等上课,但这不是出于某种奇怪的原因。我相信这是因为我没有声明字段,但不确定 import java.io.*; public class HighSchool { // Constructors public HighSchool() { } public HighSchool(String title, String teacher, int

这不应该是客户机类。我只是在给别人上课。我在一所高中用这个。例如,我为
地址
老师
学生
校长
房间号
,等等上课,但这不是出于某种奇怪的原因。我相信这是因为我没有声明字段,但不确定

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;
}
import java.io.*;
公立高中{
//建设者
公立高中(){}
公立高中(字符串标题、字符串教师、整数房间号、字符串句点、字符串[]学生、字符串地址、字符串主题){
this.title=标题;
这个老师=老师;
this.roomNumber=roomNumber;
这个周期=周期;
this.String[]students=students;
字符串地址=一个地址;
这个.String主题=主题;
}
公共课堂课程(字符串标题、字符串教师、整数房间号、字符串句点、字符串[]学生、字符串地址、字符串主题
私有字符串周期;){
公共字符串gettitle(){
返回标题;
}
公共无效集合标题(字符串标题){
this.title=标题;
}
公共字符串getteacher(){
归国教师;
}
公共空白设置器(字符串教师){
这个老师=老师;
}
public int getroomNumber(){
返回房间号;
}
公共无效setroomNumber(内部roomNumber){
this.roomNumber=roomNumber;
}
公共字符串getperiod(){
返回getperiod();
}
公共无效设置周期(字符串周期){
这个周期=周期;
}
公共字符串[]getstudents(){
返回学生[];
}
公共无效设置学生[](字符串[]学生
专用字符串地址;){
这个。学生=学生;
}
公共字符串getaddress(){
回信地址;
}
公共无效设置地址(字符串地址){
this.address=地址;
}
公共字符串getsubjects(){
返回主题;
}
public void setsubjects(字符串主题){
这个。主题=主题;
}
}
//修正法
公共学生(字符串学生){
字符串[]newstudents=新字符串[students.length+1];
for(int i=0;i
此外,您还编写了一些从Java编译器的角度看没有意义的东西:

私有字符串周期;){
-可能删除“)”

第二件事:

看看班级课程的声明。 这听起来有点错误,虽然它可能是这个网站的编辑或其他问题

“总体”提示—java有一个非常“智能”的编译器,在大多数情况下,它可以准确地说出代码的错误,因此,假设您是java新手,请尝试理解编译器对您说的话


祝你好运!

我注意到关于代码的一些事情:

    public String getperiod() {
        return getperiod();
    }
调用此函数时,此代码将导致无止境循环

    private String address;) {
        this.students = students;
    }
编译器将给出关于“;)”的错误。请将其更改为“()”以修复此错误


此外,您应该告诉我们更多关于它给您带来的错误。如果您不告诉我们编译器错误,我们将无法帮助您。

编译器给您带来了什么错误消息?这里有一个提示:您应该声明编译器说找不到的字段。编译器将准确地告诉您它找不到的字段!这一行ooks奇怪,字母
a
d
之间有空格:
this.String address=a address;
请删除空格。请始终包含编译器错误消息。这足以准确地告诉您它不喜欢您的输入。您最终将学会如何理解编译器试图告诉您的内容ou.如果您包含错误消息,则过程会快得多,然后我们可以用通俗易懂的英语(或接近通俗易懂的…)告诉您真正的问题是什么。然后你就知道了。:)Gnat它甚至没有给我一个编译器消息。它没有运行。正如其他人指出的那样,存在语法错误,因此它无法编译。你在使用什么不给编译器错误消息?你能改成使用这样的东西吗?否则你将花费90%的时间尝试定位e错误。
;)
这很经典-有人太习惯于键入表情符号了!