Issue
I know I'm explaining it terribly, I'm having a hard time understanding the logic of it also. What I've done is created a way for the user to enter in how many rooms (up to 5) to be created in this calculator. What I don't know how to do, is create the next few lines that act as... placeholders(?) for (up to) 5 rooms. I've put an example below. I apologize, very new to Java.
System.out.print ("Please enter the number of rooms! (Up to 5!) ");
int roomcount = sc.nextInt();
String[] places = new String[roomcount];
for(int i = 0; i < places.length; i++) {
places[i] = "Place Number: " + i;
}
sc.nextLine();
System.out.println("You said that there were " + roomcount + " rooms!");
System.out.print ("Please enter the types of rooms (up to " +roomcount+ ") that fill up the " + roomcount + " rooms!\n"
+ "(Rooms like Living, Dining, Bedroom1-2, Kitchen, Bathroom, etc!) \n ") ;
String roomname1 = sc.next();
String roomname2 = sc.next(); <------ I know these lines are redundant.
I'm just unsure of how to put the idea into action.
Thanks for any help!
Solution
You can create an array to add the types of rooms:
String[] types = new String[roomcount];
for(int i = 0; i < types.length; i++) {
System.out.print ("Please enter the types of room " + places[i]);
String roomName = sc.next();
types[i] = roomName;
System.out.println("Room name: " + roomName);
}
Answered By - Thành Kim Nguyễn
Answer Checked By - Katrina (JavaFixing Volunteer)