CIS 27P

Java For Programmers

Homework #3

Due: 8/02/2001

 

Assignment:

Write the following Java interface and classes:

 

Room

This interface should be in the package edu.fhda.? It should specify two methods named printInfo() and printInfoToFile(String fileName).? Concrete classes implementing Room should implement printInfo() to print labels and values of all instance variables to the console.? Similarly, they should implement printInfoToFile( String fileName ) to append the same information to the file specified by the parameter.? If the file does not exist, printInfoToFile should create the file.

 

RoomInstance

This abstract class should be in the package edu.fhda.rooms and should implement the Room interface.? It should not implement the methods printInfo() or printInfoToFile( String fileName).? It should have private instance variables for roomNumber(int) and airConditioned(boolean). A constructor should set these variables from parameter values and appropriate accessor/mutator methods should give external access to them.

 

Lecture, Lab, Combination

These classes should be derived from RoomInstance and be in the package edu.fhda.rooms.? They should each have private instance variables listed below.? Each should have a constructor that accepts parameters for all instance variables in its hiearchy.? They should also have accessor/mutator methods.

 

Lecture: numberOfDesks (int)

Lab: numberOfComputers(int)

Combination: numberOfDesks(int), numberOfComputers(int)

 

Notes:

Your diskette should have only those files pertaining to Homework #3.? Put each ?.java? and ?.class? files in a separate file and in the appropriate directory for the package name.? Put the compiled UseRooms class listed below in the root directory of your diskette.? The following command sequence must be able to run your application:

a:

java UseRooms

 

Test Class:

Use the following UseRooms class to test your classes and interface:

 

import edu.fhda.*;

import edu.fhda.rooms.*;

 

public class UseRooms

{

????? public static void main( String [] args )

????? {

??????????? Room [] roomArray = new Room[3];

 

??????????? roomArray[0] = new Lecture( 4131, false, 30 );

??????????? roomArray[1] = new Combination( 4219, true, 30, 25 );

??????????? roomArray[2] = new Lab( 4209, true, 80 );

 

??????????? for ( int c = 0; c < 3; c++ )

??????????? {

????????????????? roomArray[c].printInfo();

????????????????? roomArray[c].printInfoToFile("output.txt");

??????????? }

???????????

????? }

}

 

Expected output to both console and specified file:

Room Type: Lecture

Room Number: 4131

Air Conditioned: false

Number Of Desks: 30

 

Room Type: Combination

Room Number: 4219

Air Conditioned: true

Number of Computers: 30

Number of Desks: 25

 

Room Type: Lab

Room Number: 4209

Air Conditioned: true

Number Of Computers: 80