Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The java program you will create is to allow a user to enter the type of an apar

ID: 3911222 • Letter: T

Question

The java program you will create is to allow a user to enter the type of an apartment they would like (basement, 1st floor, 2nd floor, etc) and you will write the code that will prompt them for the floor they want to rent and you will print out the number of apartments available for that type of apartment. You will use the 2 parallel arrays, Apts[] ={5, 3,1,2} and Rents[] ={200, 350, 450, 600} ; Apts[] represents the number of apartments available for each floor – apts[0] = 5, which means there are 5 apartments available on the 0 (basement) level. Apts[1] = 3 which means there are 3 apartments available on the 1st floor, etc.   Rents[] represents the rent for each of these apartments: Rents[0] = 200 which means a basement apartment costs 200 dollars to rent.

First Goal:

Your user should be allowed to enter the amount of money they have to spend, ie : $550 and you have to determine which apartments they can rent for that amount of money.

Example: If the user enters $550, then you should output that they are able to rent from the 2nd floor and below.

Accomplish this in a method – qualify() which will return the highest floor available at the price entered by the user.

Second Goal:

Your user should be allowed to enter the floor they decide and you output the number of apartments available at that floor.

Example: If the user enters the 2nd floor, you will tell them there is 1 apartment available for that floor.

Accomplish this in a method – choice() which will return the number of apartments available on a given floor

After you output how many apartments are available, ask the user if they wish to rent an apartment on that floor.

If the user states “Yes”, then move on to Third Goal; If the user responds “No”, then prompt them for another floor. This program assumes the user will rent an apartment on at least one of the floors they can afford. You can also either user the strings “Yes” and “No” or some other Boolean means to signal they have made their choice.

Third Goal:

Thank the user for their choice, confirm their choice by outputting the apartment floor and price they have chosen, then decrement the number of apartments available in Apts[] for that floor.

Output the Apts [] array and the Rents[] array.

You MUST use the following data to get credit:

You can hardcode and initialize the following values for your arrays:

Apts[] ={5, 3,1,2} and Rents[] ={200, 350, 450, 600}

Test your code using the following data (shown with prompt text which you can customize) which should be shown in the screenshot:

Welcome to KSU Rents!

Please enter the amount of money you have to spend on an apartment:

550

You can rent an apartment on floors 2 and below.

Which floor would you like to inquire about?

2

Floor 2 has 1 apartment available

Would you like an apartment on floor 2 (Enter Yes or No)?

No

Which floor would you like to inquire about?

1

Floor 1 has 3 apartments available

Would you like an apartment on floor 1(Enter Yes or No)?

Yes

Thank you for renting with us! You have an apartment on floor 1 for 350 dollars

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

KSURents.java
==============
import java.util.Scanner;

public class KSURents {
static int Apts[] ={5, 3,1,2} ;
static int Rents[] ={200, 350, 450, 600};


public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int amount, floor;

System.out.println("Welcome to KSU Rents!");
System.out.println("Please enter the amount of money you have to spend on an apartment:");
amount = keyboard.nextInt();

floor = qualify(amount);

if(floor == -1)
System.out.println("There are no apartments for that amount!");
else
{
System.out.println("You can rent an apartment on floors " + floor + " and below");
boolean done = false;
while(!done)
{
System.out.println("Which floor would you like to inquire about?");
floor = keyboard.nextInt();
int n = choice(floor);
System.out.println("Floor " + floor + " has " + n + " apartments available");
if(n > 0)
{
System.out.println("Would you like an apartment on floor 2 (Enter Yes or No)?");
String ans = keyboard.next();
if(ans.equalsIgnoreCase("Yes"))
{
Apts[floor]--;
System.out.println("Thank you for renting with us! You have an apartment on floor " + floor +" for " + Rents[floor] + " dollars");
done = true;
}
}
}


}
}

private static int qualify(int amount)
{
int floor = -1;
for(int i = 0; i < Rents.length; i++)
{
if(Rents[i] <= amount)
floor = i;
else
break;
}

return floor;
}

private static int choice(int floor)
{
if(floor >= 0 && floor < Apts.length)
return Apts[floor];
else
return 0;
}

}


output
------
Welcome to KSU Rents!
Please enter the amount of money you have to spend on an apartment:
550
You can rent an apartment on floors 2 and below
Which floor would you like to inquire about?
2
Floor 2 has 1 apartments available
Would you like an apartment on floor 2 (Enter Yes or No)?
No
Which floor would you like to inquire about?
1
Floor 1 has 3 apartments available
Would you like an apartment on floor 2 (Enter Yes or No)?
Yes
Thank you for renting with us! You have an apartment on floor 1 for 350 dollars

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote