Define a class (static) variable to keep track of the total number of LibraryBooks cur- rently on loan.

Publish By: Admin,
Last Updated: 12-Jul-23
Price: $120

A class Television has the following fields:

private TelevisionManufacturer supplier; private String code
private int screenSize; // in inches private String type; // e.g. plasma screen

Assume that the class TelevisionManufacturer is available and that this class contains an equals method.

(a) Define a class variable, totalTVs, whose purpose is to keep track of the total number of Television objects constructed during execution of a program that uses the Television class.

(b) Declare a default constructor for this class.

(c) Declare a constructor for this class which has a formal parameter corresponding to each field.

(d) Declare an accessor method called getScreenSize whose purpose is to return the value of the screenSize field of this Television.

(e) Declare a mutator method that sets the type of this Television to a given value.

(f) Declare a method to determine whether or not this Television has been supplied by a given manufacturer.

Lab work

1. Consider the following algorithm.

(1) Randomly select a 4-digit positive number excluding 1111, 2222, ..., 9999, with leading zeros if necessary
// thus 158 would be represented by 0158 and
// 9 would be represented by 0009

(2) Let bigger denote the number obtained by taking the four digits obtained in step (1) in decreasing
order

(3) Let smaller denote the number obtained by taking the four digits obtained in step (1) in increasing order

(4) Obtain a new 4-digit number by subtracting smaller from bigger, inserting leading zeros if necessary
// e.g. 7666 - 6667 = 999, so the 4-digit value is 0999

(5) Repeat from step (2) for a maximum of 10 iterations or until two successive 4-digit numbers are identical, whichever occurs first.
Implement and test this algorithm in Java, using the Random class to generate test values.

2. This exercise is concerned with simulating the activity of a library with respect to its book-stock. You are required to write a Java application which contains a class called LibraryBook together with a main method class called LibrarySimulation.

The data about each LibraryBook consists of:
author(s) (e.g. Lewis and Loftus)
title (e.g. Java Software Solutions)
number of pages (e.g. 832)
library classification (e.g QA98 )
number of times borrowed (e.g 53)
current status
number of pending reservations (may not exceed 3)

Once it has been initially set, the current status of a LibraryBook is one of the following:

REFERENCE ONLY, ON LOAN, AVAILABLE FOR LENDING

If the status of a LibraryBook is initially set to REFERENCE ONLY, its status will not change throughout the simulation.

If a LibraryBook is currently on-loan, a reservation may be placed on that LibraryBook but only up to a maximum of three pending reservations.

(a) Define an enum type in the LibraryBook class corresponding to the status list given above.

(b) Define the fields for the LibraryBook class corresponding to the data items given above.

(c) Define a class (static) variable to keep track of the total number of LibraryBooks cur- rently on loan.

(d) Define a single constructor with the following header:/**