Answer to Question #243117 in Java | JSP | JSF for Chadwin Fritz

Question #243117

VenueControlClass

This class has a menu control method that allows users to add a Venue or ComputerLab object to an array.

Code the attributeas and methods as specified.

1. Code an array that can hold 20 Venue objects. 2. Code the numberOfVenues attribute. 3. Code a no-argument constructor. In this constructor, a) Add 3 Venue objects to the venues array. b) Add 3 ComputerLab objects to the venues array. c) Set numberOfVenues to 6. 3 Applications Development Foundations. 4. Code a method menus() that returns an int value. This value represents the option the user has chosen from the available menu options. Required: a) Define a Scanner variable to read from the keyboard. b) Define an int value, named option. c) Display a menu in the following format: 1: Add room 2: Display rooms 3: Display problem labs 4: Exit d) Read the user’s option from the keyboard into the variable option. e) Return the option read from the keyboard.


1
Expert's answer
2021-09-29T01:19:06-0400
import java.util.Scanner;


class Venue {
	private String buildingName;
	private String roomNumber;
	private int numberSeats;


	public Venue() {


	}


	public Venue(String buildingName, String roomNumber, int numberSeats) {
		this.buildingName = buildingName;
		this.roomNumber = roomNumber;
		this.numberSeats = numberSeats;
	}


	public String getBuildingName() {
		return buildingName;
	}


	public String getRoomNumber() {
		return roomNumber;
	}


	public int getNumberSeats() {
		return numberSeats;
	}


	public void setBuildingName(String buildingName) {
		this.buildingName = buildingName;
	}


	public void setRoomNumber(String roomNumber) {
		this.roomNumber = roomNumber;
	}


	public void setNumberSeats(int numberSeats) {
		this.numberSeats = numberSeats;
	}


	@Override
	public String toString() {
		return "Venue{" + "buildingName='" + buildingName + '\'' + ", roomNumber=" + roomNumber + ", numberSeats="
				+ numberSeats + '}';
	}


	public void show() {
		System.out.println("Venue: " + "buildingName='" + buildingName + '\'' + ", roomNumber=" + roomNumber
				+ ", numberSeats=" + numberSeats);
	}


	public boolean problemVenue() {
		return false;
	}
}


class ComputerLab extends Venue {
	private int numberWorkingComputer;


	public ComputerLab() {
		super("Unknown", "0", 0);
		numberWorkingComputer = 0;
	}


	public ComputerLab(int numberWorkingComputer, String buildingName, String venueNumber, int numberOfSeats) {
		super(buildingName, venueNumber, numberOfSeats);
		this.numberWorkingComputer = numberWorkingComputer;
	}


	public void setNumberWorkingComputer(int numberWorkingComputer) {
		this.numberWorkingComputer = numberWorkingComputer;
	}


	public int getNumberWorkingComputer() {
		return numberWorkingComputer;
	}


	public void show() {
		super.show();
		System.out.println(", Number of working computers: " + numberWorkingComputer);
	}


	public boolean problemVenue() {
		return 0 > numberWorkingComputer;
	}


	@Override
	public String toString() {
		return super.toString() + ", Number of working computers: " + numberWorkingComputer;
	}
}


class VenueControl {
	// 1. Code an array that can hold 20 Venue objects.
	private Venue[] venues = new Venue[20];
	// 2. Code the numberOfVenues attribute.
	private int numberOfVenues = 0;


	// 3. Code a no-argument constructor.
	public VenueControl() {
		// In this constructor
		// a) Add 3 Venue objects to the venues array.
		venues[0] = new Venue("Name 1", "5", 3);
		venues[1] = new Venue("Name 2", "8", 4);
		venues[2] = new Venue("Name 3", "4", 1);
		// b) Add 3 ComputerLab objects to the venues array.
		venues[3] = new ComputerLab(5, "ComputerLab 1", "4", 3);
		venues[4] = new ComputerLab(2, "ComputerLab 2", "8", 1);
		venues[5] = new ComputerLab(3, "ComputerLab 3", "9", 2);
		// c) Set numberOfVenues to 6.
		this.numberOfVenues = 6;
	}


	public int menus() {
		// 4. Code a method menus() that returns an int value.
		// This value represents the option the user has chosen from the available menu
		// options.
		// Required: a) Define a Scanner variable to read from the keyboard.
		Scanner keyboard = new Scanner(System.in);
		// b) Define an int value, named option.
		// c) Display a menu in the following format:
		// 1: Add room
		// 2: Display rooms
		// 3: Display problem labs
		// 4: Exit
		System.out.println("1: Add room");
		System.out.println("2: Display rooms");
		System.out.println("3: Display problem labs");
		System.out.println("4: Exit");
		System.out.print("Your choice: ");
		// d) Read the user’s option from the keyboard into the variable option.
		int ch = keyboard.nextInt();
		keyboard.close();
		// e) Return the option read from the keyboard.
		return ch;
	}


}


public class Main {


	public static void main(String[] args) {


		VenueControl VenueControl = new VenueControl();
		VenueControl.menus();


	}


}

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