2017-10-27 17 views
-1

私はしばらくの間、このアプリケーションで作業していましたが、私は少し不満ですが、まだあきらめる準備はできていません!私はそれをコンパイルするのに問題があります。私はなってきているJava - クラスとメソッドの問題

エラーは以下のとおりです。私はそれを動作させるために行うに

TestApartment.java:45: error: method isMatched in class TestApartment cannot be applied to given types; 
       if(isMatched(apt1)) 
       ^
    required: Apartment,int,double,int 
    found: Apartment 
    reason: actual and formal argument lists differ in length 

TestApartment.java:50: error: method isMatched in class TestApartment cannot be applied to given types; 
       if(isMatched(apt2)) 
       ^
    required: Apartment,int,double,int 
    found: Apartment 
    reason: actual and formal argument lists differ in length 

TestApartment.java:55: error: method isMatched in class TestApartment cannot be applied to given types; 
       if(isMatched(apt3)) 
       ^
    required: Apartment,int,double,int 
    found: Apartment 
    reason: actual and formal argument lists differ in length 

TestApartment.java:60: error: method isMatched in class TestApartment cannot be applied to given types; 
       if(isMatched(apt4)) 
       ^
    required: Apartment,int,double,int 
    found: Apartment 
    reason: actual and formal argument lists differ in length 

TestApartment.java:65: error: method isMatched in class TestApartment cannot be applied to given types; 
       if(isMatched(apt5)) 
       ^
    required: Apartment,int,double,int 
    found: Apartment 
    reason: actual and formal argument lists differ in length 

何が必要ですか?

public class Apartment 
{ 
    int AptNumber; 
    int numBedrooms; 
    double numBathrooms; 
    int AptRent; 

public Apartment(int num, int beds, double baths, int rent) 
{ 

} 


public void setAptNumber(int num)// Accessor method for apartment number 
{ 
    AptNumber = num;  
} 

public int getAptNumber() // Gets the apartment number 
{ 
    return AptNumber; 
} 
public void setnumBedrooms(int beds) // Accessor method for bedrooms 
{ 
    int numBedrooms; 
    numBedrooms = beds; 
} 
public int getnumBedrooms() // Gets the number of bedrooms 
{ 
    return numBedrooms; 
} 
    public void setnumBathrooms(double baths) // Gets the number of bathrooms 
{ 
    double numBathrooms; 
    numBathrooms = baths; 
    } 
public double getnumBathrooms() // Accessor method for bathrooms 
{ 
    return numBathrooms; 
} 
public void setAptRent(int rent) // Accessor for rent 
{ 
    int AptRent; 
    AptRent = rent; 
} 
public int getAptRent() // Gets the amount of rent 
{ 
    return AptRent; 
} 
public void display(int num, int beds, double baths, int rent) 
{ 

} 
    public double display() 
{ 
    return display(); 
} 

} 




import java.util.Scanner; 

public class TestApartment 

{ 


public static void main(String[] args) 
{ 
    int bedrooms; 
    double bathrooms; 
    int rent; 

    // This prints out my name 
    System.out.println("Beth Salvatore"); 

    // Uses Scanner class to accept keyboard input 
    Scanner keyboard = new Scanner(System.in); 

    // Prompt user for input for minimum number of bedrooms required  
    System.out.print("Enter the minimum number of bedrooms: "); 
    bedrooms = keyboard.nextInt(); 
    // Prompt user for input for minimum number of bathroomsrooms required 
    System.out.print("Enter the minimum number of bathrooms: "); 
    bathrooms = keyboard.nextDouble(); 
    // Prompt user for input for maximum amount of rent 
    System.out.print("Enter the maximum amount of rent: "); 
    rent = keyboard.nextInt(); 

    // This creates five different 
    // Apartment objects 
    Apartment apt1 = new Apartment(101, 2, 1, 725); 
    Apartment apt2 = new Apartment(102, 2, 1.5, 775); 
    Apartment apt3 = new Apartment(103, 3, 2, 870); 
    Apartment apt4 = new Apartment(104, 3, 2.5, 960); 
    Apartment apt5 = new Apartment(105, 3, 3, 1100); 

    String isMatchedMsg = "Below are the apartments that match your search criteria: "; 
    String notMatchedMsg = "No matches were found."; 

    if(isMatched(apt1)) 
    display(apt1, isMatchedMsg); 
    else 
    display(apt1, notMatchedMsg); 

    if(isMatched(apt2)) 
    display(apt2, isMatchedMsg); 
    else 
    display(apt2, notMatchedMsg); 

    if(isMatched(apt3)) 
    display(apt3, isMatchedMsg); 
    else 
    display(apt3, notMatchedMsg); 

    if(isMatched(apt4)) 
    display(apt4, isMatchedMsg); 
    else 
    display(apt4, notMatchedMsg); 

    if(isMatched(apt5)) 
    display(apt5, isMatchedMsg); 
    else 
    display(apt5, notMatchedMsg); 
} 

    public static boolean isMatched(Apartment apt, int bedrooms, double bathrooms, int rent) 
    { 

    int count = 0; 
    int MIN_MATCH = 3; 
    boolean isMatch; 

if (apt.numBedrooms >= bedrooms) 
    count = count + 1; 
    if (apt.numBathrooms >= bathrooms) 
     count = count + 1; 
    if (apt.AptRent <= rent) 
     count = count + 1; 
    if(count >= MIN_MATCH) 
     isMatch = true; 
else 
    isMatch = false; 

    return isMatch; 
    } 
    public static void display(Apartment apt, String msg) 
    { 
    System.out.println("Here are your results your results: " + 
    "\nApartment number: " + apt.getAptNumber() + "." + 
    "\nNumber of bedrooms: " + apt.getnumBedrooms() + "." + 
    "\nNumber of bathrooms: " + apt.getnumBathrooms() + "." + 
    "\nRent: " + apt.getAptRent() + ".\n"); 
}   
} 

答えて

2

あなたのメソッドpublic static boolean isMatched(Apartment apt, int bedrooms, double bathrooms, int rent)は4つのパラメータをとります。あなたは1つのパラメータでそれをどのように呼び出すことができますか?

は、以下のようにそれを呼び出します。

if(isMatched(apt, bedrooms, bathrooms, rent)) 
関連する問題