2011-12-13 62 views
0

這不應該是一個客戶端類。我只是在爲其他人使用課程。我使用這個爲Highschool。例如,我有address,teacher,students,principal,roomnumber等的類。但它沒有編譯出於某種奇怪的原因。我相信它是因爲我沒有宣佈領域,但不確定。我應該在哪裏聲明該代碼中的字段才能編譯?

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; 
} 
+1

編譯器給你什麼錯誤信息? – Gnat

+0

_這是一個提示_:你應該聲明編譯器所說的**不能**的字段。編譯器會告訴你它找不到哪一個!這行看起來很奇怪,在字母'a'和'd'之間留有空格:'this.String address = a ddress;'刪除_white space_。 – CoolBeans

+1

_總是包含你的編譯器錯誤信息。這是足夠的,告訴你到底什麼不喜歡你的輸入。你最終會學會如何理解編譯器試圖告訴你什麼。如果你包含錯誤信息,這個過程將變得更快,然後_we_可以用簡單的英語告訴你(或者接近簡單的......)真正的問題是什麼。然後你學習。 :) – sarnold

回答

1

此外,你寫的東西,不從查看Java編譯器的點意義:

private String period;) { - 可能刪除「)」。

的第二件事:

以階級Classcourse的聲明一起來看看。 它聽起來不對,雖然它可能是本網站的編輯器或什麼的問題...

「整體」的提示 - java在大多數情況下,它可以說出什麼是錯誤的「智能」編譯器與你的代碼完全一樣,假設你是Java中的新手,試着理解編譯器對你說的話。

祝你好運!

+0

';)'這是經典 - 有人習慣於打字表情符號! –

0

有些事情我注意到了有關的代碼:

public String getperiod() { 
     return getperiod(); 
    } 

此代碼將導致一個死循環,當你調用這個函數。

private String address;) { 
     this.students = students; 
    } 

編譯器會給出關於「;)」的錯誤。將其更改爲「()」以解決此問題。

此外,你應該告訴我們更多關於它給你的錯誤。如果您不給我們編譯器錯誤,我們無法幫助您。

相關問題