Rooms and More Can you please help me the JAVA program LabIn

Rooms and More

Can you please help me the JAVA program?

LabInheritStarter.zip file:

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Building {

   public static void main(String[] args) {
       Scanner kybd = new Scanner(System.in);

       // declare an ArrayList containing Room elements
       Random rand = new Random();

       System.out.println(\"Enter \ \\t1: create classroom\ \\t2: create create elevator\" + \"\ \\t3: exit\");
       int inp = kybd.nextInt();
       while (inp != 3) {
           if (inp == 1) {
               System.out.println(\"How many chairs? \");
               int ch = kybd.nextInt();
               Room current = new Classroom(rand.nextInt(1000) + 100, ch);
               // add current to the ArrayList
           } else if (inp == 2) {
               Elevator current = new Elevator(rand.nextInt(100) + 10);
               if (rand.nextInt(2) == 0) {
                   current.up(rand.nextInt(10));
               } else {
                   current.down(rand.nextInt(10));
               }
               // add current to the ArrayList
           }
           System.out.println(\"Enter \ \\t1: create classroom\ \\t2: create create elevator\" + \"\ \\t3: exit\");
           inp = kybd.nextInt();
       }
       kybd.close();
       // create a for loop to walk through the ArrayList its elements, one per line

   }

}

=================================================

I already asked someone here, but he hasn\'t completed the program. You can take a look of his code here.

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class Building {
public static void main(String[] args) {
Scanner kybd = new Scanner(System.in);
// declare an ArrayList containing Room elements
ArrayList arrayList = new ArrayList();
Random rand = new Random();
System.out.println(\"Enter \ \\t1: create classroom\ \\t2: create create elevator\" + \"\ \\t3: exit\");
int inp = kybd.nextInt();
while (inp != 3) {
if (inp == 1) {
System.out.println(\"How many chairs? \");
int ch = kybd.nextInt();
Room current = new Classroom(rand.nextInt(1000) + 100, ch);
arrayList.add(current);
} else if (inp == 2) {
Elevator current = new Elevator(rand.nextInt(100) + 10);
if (rand.nextInt(2) == 0) {
current.up(rand.nextInt(10));
} else {
current.down(rand.nextInt(10));
}
arrayList.add(current);
}
System.out.println(\"Enter \ \\t1: create classroom\ \\t2: create create elevator\" + \"\ \\t3: exit\");
inp = kybd.nextInt();
}
kybd.close();
// create a for loop to walk through the ArrayList its elements, one per line
for(int i=0;i    System.out.println(arrayList.get(i));
}
}
}
class Room {
   private int area;
   Room(){}
   Room(int area){
       this.area = area;
   }
   public int getSquareFeet(){
       return area;
   }
   public int getCapacity(){
       return this.getSquareFeet()/9;
   }
   public String toString(){
       return this.getSquareFeet() + \" \" + this.getCapacity();
   }
}
class Classroom extends Room{
   private int noOfChairs;
   private int area;
   Classroom(int area){
       this.area = area;
   }
   Classroom(int area,int noOfChairs){
       this.area = area;
       this.noOfChairs = noOfChairs;
   }
   public int getChairs(){
       return this.noOfChairs;
   }
   public void setChiars(int chairsNumber){
       this.noOfChairs = chairsNumber;
   }
   public int getCapacity(){
       return getChairs();
   }
   public String toString(){
       return getSquareFeet()+\" \"+getCapacity()+\" \"+getChairs();
   }
}
class Elevator extends Room{
   private int currentFloor;
   private int area;
   Elevator(int area){
       this.area = area;
   }
   public void up(int floors){
       currentFloor += floors;
   }
   public void down(int floors){
       currentFloor -= floors;
   }
   public int getCurrentFloor(){
       return currentFloor;
   }
   public String toString(){
       return getSquareFeet()+\" \"+getCapacity()+\" \"+getCurrentFloor();
   }
}

Rooms and More Attached Files LablnheritStarter.zip (593 B) The attached file contains starter code for a class Building that you should use as a driver for the following set of classes. Write a class Room. A Room class contains an int instance variable for the area (in square feet) of the room one constructor that takes the area of the room as a parameter an accessor, int getSquareFeet) that returns the area of the room an accessor, int getCapacity() that returns the capacity of the room. The capacity is given by dividing the square feet by 9 (using integer division) an accessor, String toString() that returns the square feet and capacity of the room Write a class Classroom that extends Room. A Classroom class contains an int instance variable for the number of chairs in the classroom a constructor that takes the area of the classroom as a parameter a constructor that takes the area of the classroom and the number of chairs as parameters getter and setter for chairs an override for getCapacity. The capacity of a classroom is the number of chairs an accessor, String toString() that returns the square feet and capacity of the room as well as the number of chairs Write a class Elevator that extends Room. An Elevator class contains an int instance variable for the current floor of the elevator a constructor that takes the area of the elevator as a parameter a mutator void up(int floors) that increases the current floor by the parameter a mutator void down(int floors) that decreases the current floor by the parameter an accessor String toString) that returns the square feet and capacity of the elevator, as well as its current floor.

Solution

PROGRAM CODE:

Building.java

package samplepro;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class Building {
public static void main(String[] args) {
Scanner kybd = new Scanner(System.in);
// declare an ArrayList containing Room elements
ArrayList<Room> rooms = new ArrayList<Room>();
Random rand = new Random();
System.out.println(\"Enter \ \\t1: create classroom\ \\t2: create create elevator\" + \"\ \\t3: exit\");
int inp = kybd.nextInt();
while (inp != 3) {
if (inp == 1) {
System.out.println(\"How many chairs? \");
int ch = kybd.nextInt();
Room current = new Classroom(rand.nextInt(1000) + 100, ch);
rooms.add(current);
} else if (inp == 2) {
Elevator current = new Elevator(rand.nextInt(100) + 10);
if (rand.nextInt(2) == 0) {
current.up(rand.nextInt(10));
} else {
current.down(rand.nextInt(10));
}
rooms.add(current);
}
System.out.println(\"Enter \ \\t1: create classroom\ \\t2: create elevator\" + \"\ \\t3: exit\");
inp = kybd.nextInt();
}
kybd.close();
for(int i=0; i<rooms.size(); i++)
{
   System.out.println((i+ 1)+ \". \" + rooms.get(i));
}
}
}

Room.java

package samplepro;

class Room {
   private int area;
   Room(){}
   Room(int area){
   this.area = area;
   }
   public int getSquareFeet(){
   return area;
   }
   public int getCapacity(){
   return this.getSquareFeet()/9;
   }
   public String toString(){
   return \"Square feet: \" + this.getSquareFeet() + \" Capacity: \" + this.getCapacity();
   }
   }

Elevator.java

package samplepro;

class Elevator extends Room{
   private int currentFloor;
     
   Elevator(int area){
   super(area);
   }
   public void up(int floors){
   currentFloor += floors;
   }
   public void down(int floors){
   currentFloor -= floors;
   }
   public int getCurrentFloor(){
   return currentFloor;
   }
   public String toString(){
   return \"Square feet: \" + getSquareFeet()+\" Capacity: \"+getCapacity()+\" Current floor: \"+getCurrentFloor();
   }
   }

Classroom.java

package samplepro;

class Classroom extends Room{
  
   private int noOfChairs;
  
   Classroom(int area){
   super(area);
   }
   Classroom(int area,int noOfChairs){
   super(area);
   this.noOfChairs = noOfChairs;
   }
   public int getChairs(){
   return this.noOfChairs;
   }
   public void setChiars(int chairsNumber){
   this.noOfChairs = chairsNumber;
   }
   public int getCapacity(){
   return getChairs();
   }
   public String toString(){
   return \"Square feet: \" + getSquareFeet()+\" Capacity: \"+getCapacity()+\" Number of chairs: \"+getChairs();
   }
}

OUTPUT:

Enter
   1: create classroom
   2: create create elevator
   3: exit
1
How many chairs?
4
Enter
   1: create classroom
   2: create elevator
   3: exit
2
Enter
   1: create classroom
   2: create elevator
   3: exit
3
1. Square feet: 619 Capacity: 4 Number of chairs: 4
2. Square feet: 31 Capacity: 3 Current floor: -1

// the floor is set from Building class. which is a driver program so I did not change that.

Rooms and More Can you please help me the JAVA program? LabInheritStarter.zip file: import java.util.ArrayList; import java.util.Random; import java.util.Scanne
Rooms and More Can you please help me the JAVA program? LabInheritStarter.zip file: import java.util.ArrayList; import java.util.Random; import java.util.Scanne
Rooms and More Can you please help me the JAVA program? LabInheritStarter.zip file: import java.util.ArrayList; import java.util.Random; import java.util.Scanne
Rooms and More Can you please help me the JAVA program? LabInheritStarter.zip file: import java.util.ArrayList; import java.util.Random; import java.util.Scanne
Rooms and More Can you please help me the JAVA program? LabInheritStarter.zip file: import java.util.ArrayList; import java.util.Random; import java.util.Scanne

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site