CS3101-3: Programming Languages: Java
Homework 2

Reading: Java in a Nutshell, chapters 2 & 3

DUE: Tuesday, Sept 23, 11PM

Goal:

  1. Learn to create Java Classes
  2. Learn to manipulate Java Clases
  3. Have Fun!


1. Define a Class to represent a physical computer. The Class should be called Computer.java
include the folowing fields for representing the following characterisics of a computer:
Remember to choose the most logical class to reperesent the data.

Field NameValues
NameUnique Name of this computer.
ModelLaptop|Desktop|Server|Unknown
SpeedThis is in MHZ, example 200, 1000, etc
Operating_SystemWindows98|Window2000|Linux|OpenBSD|MAcOS|Amiga|XBox
MemoryAmount of RAM on Machine
MakeDell|Sony|Hp|Gateway|SUN|OTHER
Screen_Sizesize of screen
Hard_Drive_Sizesize of hard drive in gig
Include methods to get and set each of the fields. For example
public void setMemory(int size)....
public int getMemory()......
NOTE: you must include error checking , for example set memory should not take a negative number.
In this assignment you can just throw a plain Exception with a message, but if you want you can
create a new exception class called MalfunctionFeatureException.
Also include methods to compare two machines if they are equal.
last but not least have a method to print out the information on a computer.

2. Write a small program called Network.java which creates a few computer objects,
sets up information on each of them, tests if any of the machines are equal, then prints out the information about them.

3. Compile and run the program (Step 2), and submit proof of its
functioning. You can do this either by submitting a 
screenshot or a "journal", "script", or "typescript" 
log (on Unix):

$ journal
Log started
$ <run your program here>
<program output>
$ exit
Journal ended

(If "journal" doesn't work on your system, try script or
typescript insteaad -- they all work roughly the same way.)

4. Follow the homework submission instructions on the class
homepage!

 

Good Luck.