Consider for following UML description of the Room class. Room -length: double -
ID: 3572875 • Letter: C
Question
Consider for following UML description of the Room class. Room -length: double -width: double +Room () +Room (length: double, width: double)//initialize the length and width to be//the parameter values +Set (length:double, width:double)//set the width and length to the//parameter values +Area (): double//compute and return the area of the room +print (): void//print the length and width Derive a ClassRoom class from the Room class. The ClassRoom has additional data values (NumDesk) for the number of desks and (NumStudent) for the number of students in the room. The ClassRoom has a default constructor and a constructor with parameters to initialize the length, width, number of desks and number of students. The ClassRoom class has a Boolean method (Adequate) to return true if the classroom is adequate, otherwise return false. The classroom is adequate if all of the students arc able to have a desk. Also the ClassRoom class has its own version of the print method to print the length, width, number of desks and number of students. The ClassRoom Class also has its own version of the Set method to set the length, width, number of desks and number of students. Write the implementation of the ClassRoom class.Explanation / Answer
import java.util.Scanner;
class classroom extends room
{
int numdesk;
int numstu;
public:
classroom()
{
length=0;
width=0;
numstu=0;
numdesk=0;
}
classroom(double l,double w,int nd,int ns)
{
length=l;
width=w;
numdesk=nd;
numstu=ns;
}
void set()
{
Scanner input=new Scanner(System.in);
System.out.println("Enter length of the classroom : ");
length=input.nextDouble();
System.out.println("Enter width of the classroom : ");
width=input.nextDouble();
System.out.println("Enter number of desks of the classroom : ");
numdesk=input.nextInt();
System.out.println("Enter number of students of the classroom : ");
numstu=input.nextInt();
}
boolean adequate()
{
if(numdesk==numstu)
return true;
else
return false;
}
void print()
{
System.out.println("Length of the room is:"+length);
System.out.println("width of the room is:"+width);
System.out.println("Number of Desks is:"+numdesk);
System.out.println("Number of students is:"+numstu);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.