2011-01-14 29 views
-1

これはすべてbluejでコンパイルされて実行されるので、メインメソッドは必要ありません。私は多くのエラーを受け取っています。私はそれらを修正する方法がわからないので、javaに新しいです。どんな助けでも大歓迎です。Javaエラーのヘルプ

このエラーは、java.util。*;エラーがあります。

パブリッククラスLettingAgent {

private ArrayList<Property>myProperty; 
private int propertyNo; 


public LettingAgent(){ 
    myProperty = new ArrayList<Property>(); 
    propertyNo = 0; 
} 

public void addProperty(String newAddress, char newLocation, int newMonthlyRent, int newNoOfBedrooms){ 
    Property newProperty = new Property(newAddress, newLocation, newMonthlyRent, newNoOfBedrooms); 
    myProperty.add(newProperty); 
} 


public void removeProperty(int propertyNo){ 
    if(propertyNo>myProperty.size() || propertyNo<0){ 
     System.out.println("Invalid Property Number!"); 

    }else{ 
     myProperty.remove(propertyNo); 
     System.out.println("Property Successfully removed.");    
    } 
} 


public void addTenant(int propertyNo, String tenantName){ 
    if(propertyNo>myProperty.size() || propertyNo<0){ 
     System.out.println("Invalid Property Number!");   
    }else{ 
     myProperty.get(propertyNo); 
     //Property.newTenant(tenantName);    
    } 
} 


public void removeTenant(int propertyNo){ 
    if(propertyNo<myProperty.size()){ 
     myProperty.get(propertyNo); 
     //Property.removeTenant(); 
    }else{ 
     System.out.println("Invalid Property Number!"); 
    } 
} 
public void searchProperty(String searchAddress){ 
    int propertyNumber = 0;  
    for(Property Property : myProperty){ 
     myProperty.get(propertyNumber);    
     if (myProperty.get(propertyNo).equals(searchAddress)){ 
      System.out.println("Property Details: "+ Property); 
     } 
     else{ 
      System.out.println("No Such Property."); 
     } 

     if(propertyNumber>myProperty.size()){ 
      System.out.println("No Such Property.");   
     }else{ 
      break; 
     }   

    } 

} 
public void propertyList(Char location, int maxRent, int minBedrooms){ 

    for(Property Property : myProperty){ 
     if((Property.getLocation().equals(location))&& (Property.get(newMonthlyRent).equals(maxRent))&& (myProperty.get(newNoOfBedrooms).equals(minBedrooms))){ 
      System.out.println(propertyNo); 
      Property.displayDetails();        
     }else{ 
      System.out.println("Property Does Not Fit Search Criteria!"); 
     }   
    }      
} 

}

`

このされた関連クラス` //プロパティクラス パブリッククラスプロパティ{ //初期化変数 プライベート文字列のアドレス。 プライベートcharの場所。 private int monthlyRent; プライベートint noOfBedrooms; プライベートブール占有; プライベート文字列tenantName;

//constructor, to create a new property 
public Property(String newAddress, char newLocation,int newMonthlyRent, int newNoOfBedrooms){ 
    address = newAddress; 
    location = newLocation; 
    monthlyRent = newMonthlyRent; 
    noOfBedrooms = newNoOfBedrooms; 
    occupied = false; 
    tenantName = ""; 
} 

//method to return the address of created property 
public String getAddress(){ 
    return address; 
} 
//method to return the location of created property  
public char getLocation(){ 
    return location; 
} 
//method to return the rent of created property  
public int getMonthlyRent(){ 
    return monthlyRent; 
} 
//method to return the number of bedrooms of created property 
public int getNoOfBedrooms(){ 
    return noOfBedrooms; 
} 
//method to return the occupied status of created property  
public boolean getOccupied(){ 
    return occupied; 
} 
//method to return the name of the tenant of created property  
public String getTenantName(){ 
    return tenantName; 
} 
//method to set a new monthly rent 
public void newRentRate(int newMonthlyRent){ 
    monthlyRent = newMonthlyRent; 
} 
//method to set a new tenant, but only works if current property is empty 
public void newTenant(String newTenant){ 
    if(occupied){ 
     System.out.println(" ERROR! Property is already occupied. "); 
    }else{ 
     tenantName = newTenant; 
     occupied = true;  
    } 

} 
//method used to remove tenant and reset the occupied status to false 
public void removeTenant(){ 
    if(occupied){ 
     tenantName = " "; 
     occupied = false; 
    }else{ 
     System.out.println("ERROR! Property is already empty. "); 
    } 
} 
//method implements a switch statement to switch the char type in to a more understandable string type 
// and also then displays the full property details. 
public void displayDetails(){ 
    String fullLocation; 
    switch(location){ 
     case 'n': case 'N': fullLocation = " North London"; break; 
     case 's': case 'S': fullLocation = " South London"; break; 
     case 'e': case 'E': fullLocation = " East London"; break; 
     case 'w': case 'W': fullLocation = " West London"; break; 
      default: fullLocation = " unknown"; 
    } 

    System.out.println("Address :" + address); 
    System.out.println("Location :" + fullLocation); 
    System.out.println("Monthly Rent : " + monthlyRent); 
    System.out.println("Number of bedrooms : " + noOfBedrooms); 
    System.out.println("Occupied Status : " + occupied); 

    if(occupied){ 
     System.out.println("Tenants Name : " + tenantName); 
    }else{ 
     System.out.println(" "); 
    } 

} 

} '

+0

変更Property.getLocation().equals(location)はあなたが取得しているエラーを投稿いただけますか?あなたが間違いを犯していると言うと、かなり広範な声明です。 – jmort253

+0

エラーが発生した場合は、その問題を指摘することがあります。 –

+0

addTenant()およびremoveTenant()メソッド内でエラーが発生しています。実際に配列リスト内のオブジェクトの属性を追加または削除する方法がわかりません。 – user575234

答えて

2

クラスPropertyメソッドget()定義されていません。

変更Property.get(newMonthlyRent).equals(またProperty.getMonthlyRent().equals(

に、あなたがすべてのプロパティ

ArrayListの上get()方法のリストを保持しているArrayListのmyPropertyPropertyつのプロパティを混合しているようです1つのPropertyインスタンスが返されますので、addTenant()メソッドでは、myProperty.get(propertyNo).newTenant(tenantName);

ないStringを返し

UPDATE

charは、equals()メソッドを持たない。 Property.getLocation() == location

+0

ずっと、私はまだエラーが文字を取得していますif文の最後のメソッドでdereferencedすることはできません – user575234

+0

@ user575234更新 –

+0

あなたの質問に答えた場合は、それを受け入れたとマークすることを検討してください。 – num1