Write an application that creates at least five Apartment objects. Then prompt a user to enter a minimum number of bedrooms required, a minimum number of baths required, and a maximum rent the user is willing to pay. Display data for all the Apartment objects that meet the user’s criteria or No apartments met your criteria if no such apartments are available.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is the question -

Create a class named Apartment that holds an apartment number, number of bedrooms, number of baths, and rent amount. Create a constructor that accepts values for each data field. Also create a get method for each field.

Write an application that creates at least five Apartment objects. Then prompt a user to enter a minimum number of bedrooms required, a minimum number of baths required, and a maximum rent the user is willing to pay. Display data for all the Apartment objects that meet the user’s criteria or No apartments met your criteria if no such apartments are available.

This is the code I already have. It doesn't seem to like under TestApartments my apt. variable. I am unsure what to do to fix this cause it doesn't like any of my code - 

public class Apartment {
    int aptNumber;
    int bedrooms;
    double baths;
    double rent;
    public Apartment(int num, int bdrms, double bths, double rent) {
        //write code here
        aptNumber = num;

        bedrooms = bdrms;

        this.baths = bths;

        this.rent = rent;
    }
    public int getAptNumber() {
        return aptNumber;
    }
    public int getBedrooms() {
        return bedrooms;
    }
    public double getBaths() {
        return baths;
    }
    public double getRent() {
        return rent;
    }

}
 
import java.util.*;
public class TestApartments {
    public static void main (String args[]) {
        Scanner input = new Scanner(System.in);
        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);
        int bdrms;
        int baths;
        double rent;
        int count = 0;
        System.out.print("Enter minimum number of bedrooms needed >> ");
        bdrms = input.nextInt();
        System.out.print("Enter minimum number of bathrooms needed >> ");
        baths = input.nextInt();
        System.out.print("Enter maximum rent willing to pay >> ");
        rent = input.nextDouble();
        System.out.println("\nApartments meeting citeria of\nat least " + bdrms + " bedrooms, at least " + baths + " baths, and " + " no more than $" + rent + " rent:");
        //write your code here
    boolean isExist = false;
    for(int i=0; i<apts.length; i++){
    if(checkApt(apts[i], bdrms, baths, rent)){
    display(apts[i]);
    isExist = true;
}

}
if(!isExist){
System.out.println("No apartments met your criteria");
}
    }
    public static boolean checkApt(Apartment apt, int bdrms, double baths, double rent) {
        //write your code here
        if(apt.getBedrooms()>=bdrms && apt.getBaths()>=baths && apt.rent<=rent)
        return true;
        return false;
    }
    public static void display(Apartment apt) {
        System.out.println("   Apt #" + apt.getAptNumber() + "    " + apt.getBedrooms() +
                           " bedrooms, and " + apt.getBaths() + " baths. Rent $" + apt.getRent());
    }
}


Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education