Answer to Question #246179 in Java | JSP | JSF for Aubrey Eso Jozela

Question #246179
Code a method named createComputerLab(). This method has no parameters, but return a ComputerLab object. Required: a. Define a Scanner variable to read from the keyboard. b. Define variables for building name, room number, number of seats and number of working computers. Prompt the user to type data values for each of the variables and read the values from the keyboard. c. Define and create a ComputerLab object from the data read from the keyboard. d. Return this ComputerLab object. 6 Code a method displayAllRooms(). This method has no parameters and is void. This method displays all objects in the array. Required: a) Display a heading.
1
Expert's answer
2021-10-05T18:16:27-0400


package computerlab;


import java.util.Scanner;
public class ComputerLab {
private String building_name;
private int room_number;
private int number_of_seats;
private int working_computers;
ComputerLab(){
    
}
   ComputerLab(String b, int r, int n, int w){
       building_name = b;
       room_number = r;
       number_of_seats = n;
       working_computers = w;
       
   }
    
    ComputerLab createComputerLab(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter building name");
        String b = scan.next();
        System.out.println("Enter room number");
        int r = scan.nextInt();
        System.out.println("Enter  number of working computers ");
        int w = scan.nextInt();
        System.out.println("Enter  number of seats ");
        int n = scan.nextInt();
        ComputerLab lab = new ComputerLab(b,  r, n,  w);
        return lab;
    }
    
    public void show(){
      System.out.printf("Building Name: %s\nRoom number: %d\n",  building_name,room_number);
      System.out.printf("Number of seats: %d\nWorking Computers: %d\n",  number_of_seats,working_computers);
    }
    void displayAllRooms(){
      ComputerLab [] lab = new ComputerLab[2];
       System.out.println("Applications Development Foundations:");
      for(int i=0; i<2; i++){
          ComputerLab compute  = new ComputerLab();
          lab[i]  =  compute.createComputerLab();
      }
      for(int i=0; i<2; i++){
          lab[i].show();
      }
    }
    public static void main(String[] args) {
       ComputerLab lab = new ComputerLab();
       lab.displayAllRooms();
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS