9. 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 an appropriate message if no such apartments are available. Save the files as Apartment.java and TestApartments.java.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I have java code that needs to be fixed to work. I keep getting errors. I will add the code below.

Apartment:

public class Apartment // Apartment.java class

{
//members of apartment

int aptNumber;

int bedrooms;

double baths;

double rent;

//class that accepts the number of bathtoom and bedrooms and rent amount

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

aptNumber=num;

bedrooms=bdrms;

this.baths=baths;

this.rent=rent;

}
//return the no. of bedrooms in the apartment

public int getBedrooms(){

return bedrooms;

}
//Returns the number of baths in the apartment

 

TestApartment:

import java.util.*;

public class TestApartments{
public static void main(String args[]){
scanner input=new Scanner(System.in);

Apartment apts[]=new Apartment[5];

apts[0]=new Apartment(101,2,1,725);

apts[1]=new Apartment(102,2,1.5,775);

apts[2]=new Apartment(103,3,2,870);

apts[3]=new Apartment(104,3,2.5,960);

apts[4]=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.System.out.println("/nApartments meeting criteria of \nat least"+bdrms+"bedrooms, at least"+ baths+ "baths, and "+"no more than $"+rent +"rent:");

boolean isExist=false;

for(int i=0;i<apts.length:i++){

if(checkApt(apts[i],bdrms,baths,rent)){

display(apts[i]);

isExist=true;

}
}

 

They are two sperate codes

9. 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 an appropriate message if no such apartments
are available. Save the files as Apartment.java and TestApartments.java.
Transcribed Image Text:9. 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 an appropriate message if no such apartments are available. Save the files as Apartment.java and TestApartments.java.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY