Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere should i declare the field in this code in order for it to compile?
    primarykey
    data
    text
    <p>This is not supposed to be a client class. I'm just making a class for others to use. I'm using this for a <code>Highschool</code>. For example i have classes for the <code>address</code>, <code>teacher</code>, <code>students</code>, <code>principal</code>, <code>roomnumber</code>, etc..But its not compiling for some odd reason. I believe its because I'm not declaring a field but not sure. </p> <pre><code>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 &lt; students.length; i++) { newstudents[i] = students[i]; } newstudents[students.length] = student; students = newstudents; } public boolean isInClass(String students) { for (int i = 0; i &lt; 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; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload