0

I have been working on this application for a while, and I'm a bit frustrated but not ready to give up yet! I am having problems getting it to compile.

The errors I have been getting are below:

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

What do I need to do to get it to work?

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");
} 
}
MadProgrammer
348k22 gold badges243 silver badges379 bronze badges
asked Oct 27, 2017 at 3:05

1 Answer 1

2

Your method public static boolean isMatched(Apartment apt, int bedrooms, double bathrooms, int rent) takes 4 parameters. How can you call it with 1 parameter then?

Call it like below:

if(isMatched(apt, bedrooms, bathrooms, rent))
pradosh nair
9451 gold badge17 silver badges30 bronze badges
answered Oct 27, 2017 at 3:11
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.