Professional Documents
Culture Documents
//3/9/15
//Block 3
//7.1.1
public class Coin
{
public final int HEADS = 0;
public final int TAILS = 1;
private int face;
public Coin ()
{
flip();
}
public void flip ()
{
face = (int) (Math.random() * 2);
}
public int getFace ()
{
return face;
}
public String toString()
{
String faceName;
if (face == HEADS)
faceName = "Heads";
else
faceName = "Tails";
}
return faceName;
}
//Grace Bae
//3/9/15
//Block 3
//7.1.2
public class MonetaryCoin extends Coin
{
private int value;
public MonetaryCoin (int money)
{
super();
value = money;
}
}
//Grace Bae
//3/9/15
//Block 3
//7.1.3
=
=
=
=
=
=
=
new
new
new
new
new
new
new
MonetaryCoin(1);
MonetaryCoin(5);
MonetaryCoin(10);
MonetaryCoin(25);
MonetaryCoin(50);
MonetaryCoin(100);
MonetaryCoin(100);
}
----jGRASP exec: java MonetaryCoinDriver
Heads
1
Heads
5
Tails
10
Tails
25
Tails
50
Tails
100
Tails
100
(vito);
(michael);
(vincent);
(sonny);
(luca);
(tom);
(anthony);
vito.work();
michael.diagnose();
vincent.operate();
sonny.assist();
luca.administrate();
tom.answer();
anthony.sweep();
}
}
//Grace Bae
//3/9/15
//block 3
//7.2.2
public class HospitalEmployee
{
protected String name;
protected int number;
}
//Grace Bae
//3/9/15
//Block 3
//7.2.3
}
//Grace Bae
//3/9/15
//Block 3
//7.2.4
}
//Grace Bae
//3/9/15
//Block 3
//7.2.8
Vito
123
Michael 234
Heart
Vincent 645
Brain
Operating: true
Sonny
789 has 6 patients.
Luca
375 works in Business
Tom
951 works in Talking
Answering: true
Anthony 123 works in Maintenence
Sweeping: false
Vito works for the hospital.
Michael is a(n) Heart doctor.
Vincent is operating now.
Sonny is a nurse with 6 patients.
Luca works in the Business department.
Tom is answering the phone.
Anthony is not sweeping the floor.
}
}
//Grace Bae
//3/9/15
//Block 3
//7.3.2
public class ReadingMatter
{
protected String title, isbn;
public ReadingMatter (String thisTitle, String isbnNum)
{
title = thisTitle;
isbn = isbnNum;
}
public void setTitle (String thisTitle)
{
title = thisTitle;
}
public void setISBN (String isbnNum)
{
isbn = isbnNum;
}
public String getTitle()
{
return title;
}
public String getISBN()
{
return isbn;
}
public String toString()
{
return (title + "\t" + isbn);
}
public void content()
{
System.out.println ("Title: " + title);
System.out.println ("ISBN: " + isbn);
}
}
//Grace Bae
//3/9/15
//Block 3
//7.3.3
public class Book extends ReadingMatter
}
//Grace Bae
//3/9/15
//Block 3
//7.3.4
return characters;
}
public String toString()
//Grace Bae
//3/9/15
//Block 3
//7.3.6
public class Magazine extends ReadingMatter
{
protected String editor;
public Magazine (String thisTitle, String isbnNum, String ed)
{
super (thisTitle, isbnNum);
editor = ed;
}
public void setEditor (String ed)
{
editor = ed;
}
public String getEditor()
{
return editor;
}
public String toString()
{
String result = super.toString();
result += "\t" + editor;
return result;
}
public void content()
{
super.content();
System.out.println ("Editor: " + editor);
}
}
----jGRASP exec: java BookClub