SlideShare a Scribd company logo
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 rooms = 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);
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

More Related Content

Similar to Rooms and MoreCan you please help me the JAVA programLabInherit.pdf

Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Sriram Raj
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
Muhammad Fayyaz
 
Object and class
Object and classObject and class
Object and class
mohit tripathi
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
ShahinAhmed49
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
Creating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docxCreating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docx
R.K.College of engg & Tech
 
You are given a specification for some Java classes as follows.  A.pdf
You are given a specification for some Java classes as follows.  A.pdfYou are given a specification for some Java classes as follows.  A.pdf
You are given a specification for some Java classes as follows.  A.pdf
eyebolloptics
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
Sandeep Kr. Singh
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional ProgrammingEelco Visser
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
Tak Lee
 
Java -lec-5
Java -lec-5Java -lec-5
Java -lec-5
Zubair Khalid
 
JavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programmingJavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programming
Henri Tremblay
 
Java Programs
Java ProgramsJava Programs
Java Programs
vvpadhu
 
Java programs
Java programsJava programs
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
Christian Baranowski
 
The... Wonderful? World of Lambdas
The... Wonderful? World of LambdasThe... Wonderful? World of Lambdas
The... Wonderful? World of Lambdas
Esther Lozano
 

Similar to Rooms and MoreCan you please help me the JAVA programLabInherit.pdf (20)

Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Object and class
Object and classObject and class
Object and class
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Creating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docxCreating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docx
 
You are given a specification for some Java classes as follows.  A.pdf
You are given a specification for some Java classes as follows.  A.pdfYou are given a specification for some Java classes as follows.  A.pdf
You are given a specification for some Java classes as follows.  A.pdf
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
Java -lec-5
Java -lec-5Java -lec-5
Java -lec-5
 
JavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programmingJavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programming
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Java programs
Java programsJava programs
Java programs
 
Java Reflection
Java ReflectionJava Reflection
Java Reflection
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Collections
CollectionsCollections
Collections
 
The... Wonderful? World of Lambdas
The... Wonderful? World of LambdasThe... Wonderful? World of Lambdas
The... Wonderful? World of Lambdas
 

More from mumnesh

Poisson distribution] The number of data packets arriving in 1 sec at.pdf
Poisson distribution] The number of data packets arriving in 1 sec at.pdfPoisson distribution] The number of data packets arriving in 1 sec at.pdf
Poisson distribution] The number of data packets arriving in 1 sec at.pdf
mumnesh
 
Problem 1 Create Node class (or use what you have done in Lab4)• .pdf
Problem 1 Create Node class (or use what you have done in Lab4)• .pdfProblem 1 Create Node class (or use what you have done in Lab4)• .pdf
Problem 1 Create Node class (or use what you have done in Lab4)• .pdf
mumnesh
 
One of your friends has several brothers and sisters, each quite dif.pdf
One of your friends has several brothers and sisters, each quite dif.pdfOne of your friends has several brothers and sisters, each quite dif.pdf
One of your friends has several brothers and sisters, each quite dif.pdf
mumnesh
 
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdfMalpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
mumnesh
 
In JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdfIn JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdf
mumnesh
 
How does Pb and TCE partition between components of soil (mineral, o.pdf
How does Pb and TCE partition between components of soil (mineral, o.pdfHow does Pb and TCE partition between components of soil (mineral, o.pdf
How does Pb and TCE partition between components of soil (mineral, o.pdf
mumnesh
 
Hi, please I need help with the correct answer to the above multiple.pdf
Hi, please I need help with the correct answer to the above multiple.pdfHi, please I need help with the correct answer to the above multiple.pdf
Hi, please I need help with the correct answer to the above multiple.pdf
mumnesh
 
For which phyla are megaspores a shared trait Bryophyta Monilophyt.pdf
For which phyla are megaspores a shared trait  Bryophyta  Monilophyt.pdfFor which phyla are megaspores a shared trait  Bryophyta  Monilophyt.pdf
For which phyla are megaspores a shared trait Bryophyta Monilophyt.pdf
mumnesh
 
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdfFor Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
mumnesh
 
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdfFor analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
mumnesh
 
Fill in the blank. A contingency table relates only continuous rando.pdf
Fill in the blank. A contingency table relates  only continuous rando.pdfFill in the blank. A contingency table relates  only continuous rando.pdf
Fill in the blank. A contingency table relates only continuous rando.pdf
mumnesh
 
Discuss the dangers associated with hydrogen sulfide in the petro.pdf
Discuss the dangers associated with hydrogen sulfide in the petro.pdfDiscuss the dangers associated with hydrogen sulfide in the petro.pdf
Discuss the dangers associated with hydrogen sulfide in the petro.pdf
mumnesh
 
Complete the following paragraph to describe the various reproductive.pdf
Complete the following paragraph to describe the various reproductive.pdfComplete the following paragraph to describe the various reproductive.pdf
Complete the following paragraph to describe the various reproductive.pdf
mumnesh
 
CommunicationsSystems have four basic properties (holism, equi-fi.pdf
CommunicationsSystems have four basic properties (holism, equi-fi.pdfCommunicationsSystems have four basic properties (holism, equi-fi.pdf
CommunicationsSystems have four basic properties (holism, equi-fi.pdf
mumnesh
 
Based on your reading of the GCU introduction and the textbooks, wha.pdf
Based on your reading of the GCU introduction and the textbooks, wha.pdfBased on your reading of the GCU introduction and the textbooks, wha.pdf
Based on your reading of the GCU introduction and the textbooks, wha.pdf
mumnesh
 
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdfAnswer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
mumnesh
 
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdfAbraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
mumnesh
 
29. This figure shows the principal coronary blood vessels. Which one.pdf
29. This figure shows the principal coronary blood vessels. Which one.pdf29. This figure shows the principal coronary blood vessels. Which one.pdf
29. This figure shows the principal coronary blood vessels. Which one.pdf
mumnesh
 
14. Suppose I have collected the names of people in several separate.pdf
14. Suppose I have collected the names of people in several separate.pdf14. Suppose I have collected the names of people in several separate.pdf
14. Suppose I have collected the names of people in several separate.pdf
mumnesh
 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf
mumnesh
 

More from mumnesh (20)

Poisson distribution] The number of data packets arriving in 1 sec at.pdf
Poisson distribution] The number of data packets arriving in 1 sec at.pdfPoisson distribution] The number of data packets arriving in 1 sec at.pdf
Poisson distribution] The number of data packets arriving in 1 sec at.pdf
 
Problem 1 Create Node class (or use what you have done in Lab4)• .pdf
Problem 1 Create Node class (or use what you have done in Lab4)• .pdfProblem 1 Create Node class (or use what you have done in Lab4)• .pdf
Problem 1 Create Node class (or use what you have done in Lab4)• .pdf
 
One of your friends has several brothers and sisters, each quite dif.pdf
One of your friends has several brothers and sisters, each quite dif.pdfOne of your friends has several brothers and sisters, each quite dif.pdf
One of your friends has several brothers and sisters, each quite dif.pdf
 
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdfMalpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
Malpighiaceae luonanthaceae Ochnaceae Flacourtiaceae O Monilophytes G.pdf
 
In JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdfIn JavaWrite a program that reads a text file that contains a gra.pdf
In JavaWrite a program that reads a text file that contains a gra.pdf
 
How does Pb and TCE partition between components of soil (mineral, o.pdf
How does Pb and TCE partition between components of soil (mineral, o.pdfHow does Pb and TCE partition between components of soil (mineral, o.pdf
How does Pb and TCE partition between components of soil (mineral, o.pdf
 
Hi, please I need help with the correct answer to the above multiple.pdf
Hi, please I need help with the correct answer to the above multiple.pdfHi, please I need help with the correct answer to the above multiple.pdf
Hi, please I need help with the correct answer to the above multiple.pdf
 
For which phyla are megaspores a shared trait Bryophyta Monilophyt.pdf
For which phyla are megaspores a shared trait  Bryophyta  Monilophyt.pdfFor which phyla are megaspores a shared trait  Bryophyta  Monilophyt.pdf
For which phyla are megaspores a shared trait Bryophyta Monilophyt.pdf
 
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdfFor Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
For Programming Embedded SystemsQ-07 Whcih variable and condition.pdf
 
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdfFor analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
For analysis of Thermodynamic Cycle, we draw T-s or P-h diagram. Why.pdf
 
Fill in the blank. A contingency table relates only continuous rando.pdf
Fill in the blank. A contingency table relates  only continuous rando.pdfFill in the blank. A contingency table relates  only continuous rando.pdf
Fill in the blank. A contingency table relates only continuous rando.pdf
 
Discuss the dangers associated with hydrogen sulfide in the petro.pdf
Discuss the dangers associated with hydrogen sulfide in the petro.pdfDiscuss the dangers associated with hydrogen sulfide in the petro.pdf
Discuss the dangers associated with hydrogen sulfide in the petro.pdf
 
Complete the following paragraph to describe the various reproductive.pdf
Complete the following paragraph to describe the various reproductive.pdfComplete the following paragraph to describe the various reproductive.pdf
Complete the following paragraph to describe the various reproductive.pdf
 
CommunicationsSystems have four basic properties (holism, equi-fi.pdf
CommunicationsSystems have four basic properties (holism, equi-fi.pdfCommunicationsSystems have four basic properties (holism, equi-fi.pdf
CommunicationsSystems have four basic properties (holism, equi-fi.pdf
 
Based on your reading of the GCU introduction and the textbooks, wha.pdf
Based on your reading of the GCU introduction and the textbooks, wha.pdfBased on your reading of the GCU introduction and the textbooks, wha.pdf
Based on your reading of the GCU introduction and the textbooks, wha.pdf
 
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdfAnswer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
Answer using Giardias, Shiga-toxin producing E.coli1.Causative Agn.pdf
 
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdfAbraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
Abraham Shine recently opaned his own accounting fiem on April 1, whi.pdf
 
29. This figure shows the principal coronary blood vessels. Which one.pdf
29. This figure shows the principal coronary blood vessels. Which one.pdf29. This figure shows the principal coronary blood vessels. Which one.pdf
29. This figure shows the principal coronary blood vessels. Which one.pdf
 
14. Suppose I have collected the names of people in several separate.pdf
14. Suppose I have collected the names of people in several separate.pdf14. Suppose I have collected the names of people in several separate.pdf
14. Suppose I have collected the names of people in several separate.pdf
 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf
 

Recently uploaded

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 

Rooms and MoreCan you please help me the JAVA programLabInherit.pdf

  • 1. 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
  • 2. } } ================================================= 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
  • 3. 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; }
  • 4. 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
  • 5. 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 rooms = 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); 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));
  • 6. } 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