Dynamic and Distributed Scheduling in Communication

Download Report

Transcript Dynamic and Distributed Scheduling in Communication

CSD Univ. of Crete
Fall 2008
Applying Inheritance to Solve problems
1
Fall 2008
CSD Univ. of Crete
Classification, Generalization and Specialization
 Classification
the
act of identifying and categorizing similar objects into
classes is known as classification
the resulting categories are known as classes which form
meaningful abstractions for organizing information
Objects
Julia
Angela
Lawrence
Alex
Roles
a customer
a secretary
a salesperson
a customer
Objects
Peter
John
Chris
Anna
Roles
a salesperson
a manager
a customer
a manager
List of people objects in a furniture shop
2
Fall 2008
CSD Univ. of Crete
Classification, Generalization and Specialization
Customer
- Alex
- Julia
- Chris
SalesPerson
- Lawrence
- Peter
Manager
Secretary
- John
- Anna
- Angela
3
Fall 2008
CSD Univ. of Crete
Classification, Generalization and Specialization
 Generalization
generalization
is the act of capturing similarities between classes
and defining the similarities in a new generalized class
the original classes are known as subclasses, and the generalized
class is known as superclass
Employee
superclass
SalesPerson
Manager
- Lawrence
- Peter
- John
- Anna
Secretary
- Angela
4
Fall 2008
CSD Univ. of Crete
Classification, Generalization and Specialization
 Specialization
specialization
is the act of capturing differences among objects in
a class and creating new distinct subclasses with the differences
PeopleInFS
Customer
- Alex
- Julia
- Chris
Employee
subclass
5
Fall 2008
CSD Univ. of Crete
Classification, Generalization and Specialization
Super-
and sub-classes can be organized into a class hierarchy
with the superclasses placed toward the top of the hierarchy and
the subclasses toward the bottom of the hierarchy
PeopleInFS
Customer
SalesPerson
superclass
Employee
Manager
superclass and
subclass
Secretary
subclass
which
class an object is referred to in a class hierarchy is a matter
of generality
6
Fall 2008
CSD Univ. of Crete
Inheritance Example: People in Furniture Shop
name
address
budget
getName( )
getBudget( )
placeOrder( )
PeopleInFS
Customer
name
employeeNum
commission
getName( )
getEmployeeNum( )
getCommission( )
takeOrder( )
SalesPerson
name
getName( )
Employee
Manager
name
employeeNum
getName( )
getEmployeeNum()
Secretary
7
Fall 2008
CSD Univ. of Crete
Inheritance Example: People in Furniture Shop
PeopleInFS
- name: String
+ getName( ): String
Customer
- address: String
- budget: int
+ getBudget( ): int
+ placeOrder( ): void
“inherits from ”
(or “is-a ”)
Employee
- employeeNum: int
+ getEmployeeNum( ): int
SalesPerson
Manager
- commission: int
- allowance: int
+ getCommission( ): int
+ getAllowance( ): int
takeOrder( ): int
Secretary
8
Fall 2008
CSD Univ. of Crete
Inheritance Example: People in Furniture Shop
SalesPerson
Employee
PeopleInFS
+ getCommission( ): int
+ takeOrder( ): int
+ getName( ): String
- name: String
+ getEmployeeNum( ): int
- employeeNum: int
- commission: int
9
Fall 2008
CSD Univ. of Crete
Inheritance and Java Classes/Interfaces
subclass
or
superclass
extends
derived class
or
base class
subinterface
extends
superinterface
class
implements
interface
10
Fall 2008
CSD Univ. of Crete
Applied Inheritance
 Decide on the classes involved from the problem description
Group classes into conceptually equivalent groups
Per group of classes, the generalizing concept will be a Parent to
those classes
Distribute responsibilities amongst all classes based on what is
appropriate and customary for that class
 Example: A program to teach geometry needs to model some basic
shapes
All shapes have surface area, could have volume and location
The shapes that need to be modeled are: Circle, Rectangle, Sphere,
Cylinder, and a Square
 What classes will you need?
11
Fall 2008
CSD Univ. of Crete
A Geometry Example
Classes: Circle, Rectangle, Sphere, Cylinder, Square, Coordinate
2D Shapes
Group classes
All “Shapes”
Circle
Sphere
Rectangle
Coordinate
Cylinder
Square
Square is a Rectangle
3D Shapes
Shape
Shapes2D
Inheritance hierarchy
Circle
Rectangle
Square
Shapes3D
Cylinder
Sphere
12
Fall 2008
CSD Univ. of Crete
A Geometry Example
Shape
Shapes2D
Circle
Shapes3D
Rectangle
Cylinder
Sphere
Square
Distribute Responsibilities:
Shape
Shape2D
Shape3D
+getSurfaceArea()
+clone()
+equals()
+toString()
+Object getLocation()
+ ?
+getVolume()
Is Shape2D needed?
13
Fall 2008
CSD Univ. of Crete
Example … Abstract classes
public abstract class Shape{
double getSurfaceArea();
Object getLocation();
Object clone();
String toString();
boolean equals();
}
.
public interface
Shape{
double getSurfaceArea();
Object getLocation();
Object clone();
String toString();
boolean equals();
}
Observe the syntax of Shape
The methods are not
virtual methods
Abstract Class: A class with at least
one unimplemented method
Interface: A class with only
unimplemented methods
14
Fall 2008
CSD Univ. of Crete
Sample Interfaces
Q: How do you inherit from an interface?
A: By implementing the interface
public interface Shape implements Cloneable{
...
}
public abstract class Shape2D implements Shape{
...
}
Q: How do you inherit from an Abstract class?
A: The usual way, by extending
public class Circle extends Shape2D{
…
}
15
Fall 2008
CSD Univ. of Crete
Its All Still Inheritance!
public interface Shape extends Clonable{
…
}
public abstract class Shape2D implements Shape{
…
}
public class Circle extends Shape2D{
Circle has to implement all
unimplemented methods of
• 2DShape
• Shape
• Clonable
}
16
Fall 2008
CSD Univ. of Crete
Its All Still Inheritance!
Client Code
…
Circle c = new Circle();
…
Shape s = c;
Cloneable cln = s;
Shape2D s2d = s;
Through c you can access ALL methods
of Circle AND its parents!
Through s you can access ONLY methods
of Shape and Cloneable implemented in
Circle
Through cln you can access ONLY methods
of Cloneable implemented in Circle
Through s2d you can access ONLY
methods of Shape, Cloneable, and
Shape2D implemented in Circle
17
Fall 2008
CSD Univ. of Crete
The Class Rectangle
public class Rectangle extends Shape2D{
private int width,length;
public Rectangle(int w,int l){
width = w;
length = l;
}
public int getSurfaceArea(){
return(width*length);
}
18
Fall 2008
CSD Univ. of Crete
The Class Rectangle
public boolean equals(Object o){
if(!o instanceOf Rectangle)
return false
Rectangle r = (Rectangle)o;
if (this.width != r.width)
return false;
if (this.length!=r.length)
return false;
return true;
}
19
Fall 2008
CSD Univ. of Crete
The Class Rectangle
public void toString(){
System.out.println(“Rectangle”+width+” “+length);
}
public Object clone(){
return(new Rectangle(width,length);
}
public Object getLocation(){
…
}
20
Fall 2008
CSD Univ. of Crete
The Class ShapePair
public abstract class ShapePair extends Shape{
private Shape shape1,shape2;
public ShapePair(Shape s1,Shape s2){
shape1 = s1;
shape2 = s2;
}
public int getSurfaceArea(){
return(shape1.getSurfaceArea()
+shape2.getSurfaceArea());
}
21
Fall 2008
CSD Univ. of Crete
The Class Rectangle
public Object clone(){
Shape s1 = (Shape)shape1.clone();
Shape s2 = (Shape)shape2.clone();
return(new ShapePair(s1,s2);
}
 A very
simple example of grouping two shapes!
22
Fall 2008
CSD Univ. of Crete
Understanding Polymorphism
 Static vs dynamic binding


binding refers to the association of a method invocation and the code
to be executed on behalf of the invocation
in static binding, all the associations are determined at compile time
 conventional function calls are statically bound
char shapeType[numShapes];
struct circle circles[numCircles];
struct square squares[numSquares];
int c = 0, s = 0;
...
for (i = 0; i < numShapes; i++)
switch (shapeType[i]) {
‘c’: calculateCircleArea(circles[c++]); break;
‘s’: calculateSquareArea(squares[s++]); break;
}
23
Fall 2008
CSD Univ. of Crete
Understanding Polymorphism
 in
dynamic binding, the code to be executed in response to a method
invocation (i.e., a message) will not be determined until runtime
 method invocations to variable shapeArray (in the following
example) are dynamically bound
public class ShapeDemoClient {
public static void main(String argv[ ]) {
Circle c1 = new Circle("Circle C1");
Circle c2 = new Circle("Circle C2", 3.0f);
Square s1 = new Square("Square S1");
Square s2 = new Square("Square S2", 3.0f);
Shape shapeArray[ ] = {c1, s1, c2, s2};
for (int i = 0; i < shapeArray.length; i++) {
System.out.println("The area of " +
shapeArray[i].getName( ) + " is " +
shapeArray[i].calculateArea( ) + " sq. cm."); }
} // End main
} // End ShapeDemoClient1 class
24
Fall 2008
CSD Univ. of Crete
Avoid Confusion Between Is-A and Has-A
 Improper class hierarchies are commonly created when designers
confuse is-a with has-a
“is-a” relation: the extension creates a new class that is kind of the
original class, e.g,
Rectangle
Square
“has-a”
relation: an object of one class uses objects of other
classes to store state or do work
circle
*
1
vehicle is-a Movable Abstraction
A vehicle is-a Physical Abstraction
A vehicle has-a location
A vehicle is-not-a Point (the class of location)
point
A
25
Fall 2008
CSD Univ. of Crete
Composition versus Inheritance
 All aspects of the protocol are
part of child’s interface
 Requires us to explicitly send
messages to the class
 Restricts operations on child to
those that are applicable
 Creates an independent type
 Makes the use of the parent
structure an implementation
detail that can easily be
changed
 Requires us to look at the




parent’s as well as child’s protocol
Reuses the parent’s code with no
explicit references
Allows all the parent operations to
be applied, even those that are
meaningless for the child
Allows us to use the child
anywhere the parent can be used
Ties the child to choice of the
parent structure
26
Fall 2008
CSD Univ. of Crete
BankAccount hierarchy
Object
We will write this
class later
BankAccount
JointBankAccount
Every Java class inherits from the top level Object class.
The Object class is the ultimate parent of every Java class
27
Fall 2008
CSD Univ. of Crete
BankAccount Examples
 Declare two accounts
BankAccount fred = new
BankAccount(123, "Fred", 345.50);
JointBankAccount fredMary = new
JointBankAccount(345, "Fred", "Mary", 450,65);
 A joint account is a type of account:
BankAccount ellenFrank = new
JointBankAccount(456, "Ellen", "Frank", 3450);
 The following statement is illegal
JointBankAccount fred = new
BankAccount(123, "Fred", 345.50);
28
Fall 2008
CSD Univ. of Crete
BankAccount Examples
 Consider the two accounts
JointBankAccount fredMary = new
JointBankAccount(345, "Fred", "Mary", 450,65);
BankAccount ellenFrank = new
JointBankAccount(456, "Ellen", "Frank", 3450);
 The following statements are legal
String owner = fredMary.getOwner();
String jointOwner = fredMary.getJointOwner();
 The 2nd statement is illegal
String owner = fredMary.getOwner();
String jointOwner = ellenFrank.getJointOwner();
29
Fall 2008
CSD Univ. of Crete
AccountReader Example
 Problem: Write an AccountReader class that can read both
BankAccount and JointBankAccount objects.
 Suggests that we need two methods with prototypes
public BankAccount readBankAccount()
public JointBankAccount readJointBankAccount()
 Because of polymorphism only the first version is needed: a joint
account "is an" account.
30
Fall 2008
CSD Univ. of Crete
AccountReader Example
package booklib;
import booklib.BankAccount;
import booklib.JointBankAccount;
import booklib.KeyboardReader;
public class AccountReader
{
private KeyboardReader input =
new KeyboardReader();
public BankAccount readAccount() {...}
}
31
Fall 2008
CSD Univ. of Crete
AccountReader Example
public BankAccount readAccount()
{
// declare local vars
// read account type
// read number, balance, owner
if (type == 2)
{
// read joint owner name
return new JointBankAccount(...);
}
else
return new BankAccount(...);
}
it's also a
BankAccount
32
Fall 2008
CSD Univ. of Crete
AccountReaderTester
import booklib.*;
public class AccountReaderTester
{
public AccountReaderTester()
{
AccountReader accountInput = new
AccountReader();
BankAccount a = accountInput.readAccount();
System.out.println(a);
}
public static void main(String[] args)
{ new AccountReaderTester();
}
}
33
Fall 2008
CSD Univ. of Crete
toString is polymorphic
 The print statement
System.out.println(a);
is shorthand for
System.out.println(a.toString());
 the Java run-time system knows whether a refers to a BankAccount
object or to a JointBankAccount object so it calls the correct
version of the two toString methods
34
Fall 2008
CSD Univ. of Crete
Bank Account Processing
 Problem: Read an array of BankAccount objects and process them
in several ways.
 Reading the array is common to all processors
 Therefore we start with an abstract account processor class that has
a non-abstract method to do the account reading and provides an
abstract method for account processing
 Each subclass will provide its own implementation of the processor
method.
35
Fall 2008
CSD Univ. of Crete
AccountProcessor
abstract public class AccountProcessor
{ private AccountReader inputAccount =
new AccountReader();
protected KeyboardReader console =
new KeyboardReader();
protected BankAccount[] account;
public void readAccounts(){...}
subclasses will
need to access
them
semi-colon
is necessary
abstract public void processAccounts();
}
keyword to indicate
abstract classes and methods
36
Fall 2008
CSD Univ. of Crete
readAccounts Method
public void readAccounts()
{
System.out.println("How many accounts?");
int size = input.readInt();
account = new BankAccount[size];
for (int k = 0; k < account.length; k++)
{
account[k] = inputAccount.readAccount();
}
}
37
Fall 2008
CSD Univ. of Crete
MaxBalanceProcessor
public class MaxBalanceProcessor
extends AccountProcessor
{
public void processAccounts()
{
double max = account[0].getBalance();
for (int k = 1; k < account.length; k++)
{
double b = account[k].getBalance();
if (b > max) max = b;
}
System.out.println{
"The maximum balance is " + max);
}
}
implement the
processAccounts
method
38
Fall 2008
CSD Univ. of Crete
MaxBalanceProcessorRunner
public class MaxBalanceProcessorRunner
{
public static void main(String[] args)
{
MaxBalanceProcessor program =
new MaxBalanceProcessor();
program.readAccounts();
program.processAccounts();
}
}
calls method in
AccountProcessor
39
Fall 2008
CSD Univ. of Crete
A Fund Transfer Method
 Problem: Write a method that can be used to transfer a given amount
from one bank account to another that works with both BankAccount
and JointBankAccount objects:
 Without polymorphic types we would need four different methods to
cover the four possible types of transfer (bank to bank, joint to joint,
bank to joint and joint to bank)
 With polymorphism only one method is needed
40
Fall 2008
CSD Univ. of Crete
A Fund Transfer Method
public void transfer(BankAccount from,
BankAccount to, double amount;
{
boolean ok = from.withdraw(amount);
if (ok)
{
to.deposit(amount);
}
}
 This works because a JointBankAccount "is a"
BankAccount
41
Fall 2008
CSD Univ. of Crete
Using the Method
BankAccount fred = new BankAccount(...);
BankAccount joan = new BankAccount(...);
JointBankAccount fredMary =
new JointBankAccount(...);
JointBankAccount joanBob =
new JointBankAccount(...);
transfer(fred, joan, 89.55);
transfer(fred, fredMary, 49.35);
transfer(joanBob, fredMary, 100.00);
transfer(joanBob, joan, 50.00);
42
Fall 2008
CSD Univ. of Crete
Employee Hierarchy
Employee
Everything common
to all employees
Manager
HourlyWorker
PartTimeWorker
CommissionWorker
These differ only
in how the salary
is calculated
43
Fall 2008
CSD Univ. of Crete
Abstract Employee Class
abstract public class Employee
{
private String name;
public Employee(String name)
{ this.name = name;
}
public String getName()
{ return name;
}
abstract public double grossSalary();
abstract public double netSalary();
Constructor for
the name part
polymorphic
methods
}
44
Fall 2008
CSD Univ. of Crete
Subclasses
 Manager
gross monthly salary,10% deductions.
 HourlyWorker
 gross monthly salary from hours worked and hourly wage, 5%
ideductions.
 PartTimeWorker
 as above with not deductions
 CommissionWorker
 like manager with a commission as a percentage of monthly sales

45
Fall 2008
CSD Univ. of Crete
The Manager Class
public class Manager extends Employee
{
protected double gross;
protected double net;
public Manager(String name, double salary)
{
call superclass
super(name);
constructor to
gross = salary;
do its part
net = 0.9 * gross;
}
public double grossSalary() { return gross; }
public double netSalary() { return net; }
public String toString() {...}
}
46
Fall 2008
CSD Univ. of Crete
ProcessEmployees
public Employee[] staff;
...
a polymorphic loop
public void doCalculations()
{ totalGrossSalary = totalNetSalary = 0.0;
for (int k = 0; k < staff.length; k++)
{
totalGrossSalry += staff[k].grossSalary();
totalNetSalary += staff[k].netSalary();
System.out.println(staff[k]);
}
totalBenefits =
totalGrossSalary - totalNetSalary
}
47
Fall 2008
CSD Univ. of Crete
What is an Adapter Class?
 Inheritance always adds functionality.
 Sometimes we need to subtract functionality.
 For example we may want to make a class serve a more specific or
simpler purpose by hiding some of its methods.
 Adapter classes use composition to do this.
 Our custom format class is an example: hiding the complexity of the
DecimalFormat class.
48
Fall 2008
CSD Univ. of Crete
The java.util.Vector class
 This is a generic dynamic container class. Some of its
constructors and methods are
public Vector()
public Vector(int initialCapacity)
public void addElement(Object obj)
public Object elementAt(int k)
public void setElementAt(int k)
public int size()
// convert vector to an Object array
public Object[] toArray()
// convert to array of specified type
public Object[] toArray(Object[] obj)
49
Fall 2008
CSD Univ. of Crete
Vector with BankAccount
 Storing BankAccount objects in a Vector container
Vector v = new Vector();
v.addElement(new BankAccount(123,"Fred",345.50);
v.addElement(new BankAccount(345,"Mary",435.43);
System.out.println(v.elementAt(0));
System.out.println(v.elementAt(1));
BankAccount b = (BankAccount) v.elementAt(0);
Object amnesia
again
50
Fall 2008
CSD Univ. of Crete
Vector with BankAccount
 Converting a Vector to an array
Vector v = new Vector(1000);
...
BankAccount[] a = new BankAccount[v.size()];
a = (BankAccount[]) v.toArray(a);
Object amnesia
again
51
Fall 2008
CSD Univ. of Crete
BankAccountVector Class
package booklib;
import java.util.Vector;
public class BankAccountVector
{
private Vector v; // composition (hide it)
public BankAccountVector() {...}
public BankAccountVector(int initialCap){...}
public void addAccount(BankAccount b) {...}
public BankAccount getAccount(int k) {...}
public void replaceAccount(BankAccount b,
int k) {...}
public int size() {...}
public BankAccount[] toArray() {...}
}
52
Fall 2008
CSD Univ. of Crete
BankAccountVector Class
Constructors
public BankAccountVector()
{
v = new Vector();
}
public BankAccountVector(int initialCap)
{
v = new Vector(initialCapacity);
}
53
Fall 2008
CSD Univ. of Crete
BankAccountVector Class
Methods
public void addAccount(BankAccount b)
{
v.addElement(b);
}
public BankAccount getAccount(int k)
{
return (BankAccount) v.elementAt(k);
}
54
Fall 2008
CSD Univ. of Crete
BankAccountVector Class
Methods
public void replaceAccount(BankAccount b, int k)
{ v.setElementAt(b,k);
}
public int size()
{ return v.size();
}
public BankAccount[] toArray()
{ BankAccount[] b = new BankAccount[v.size()];
return (BankAccount[]) v.toArray(b);
}
55
Fall 2008
CSD Univ. of Crete
A Harder Example
A Stack Machine is a device that lets you write simple programs that
use a Stack
Items (in our example numbers) are placed on and removed from the
stack using two commands “push” to place on, and “pop” to take off
Items are always placed on top of the stack and taken off the top of
the stack
A stack is a last-in-first-out structure
Arithmetic operations can be performed by assuming that the two
operands needed for the operation will be the top two items on the stack
and the answer will be placed back on the stack
56
Fall 2008
CSD Univ. of Crete
A Harder Example
push 5
add
push 10
10
5
5
15
Stack
Stack
Stack
Any mathematical expression can be converted into a series of machine instructions
5 + (6 * (5 - 4))
push 5
push 4
subtract
push 6
multiply
push 5
add
print
57
Fall 2008
CSD Univ. of Crete
A Harder Example
Clients view:
What are the classes?
public static void main(String[] args){
StackMachine sm = new StackMachine();
sm.load(“programFileName”);
sm.run();
}
StackMachine
Coordinate
all operations
ProgramLoader
void load(String fileName)
void run()
Its purpose is to read the
program in
void load(String filename)
void String getInstruction(int i)
int numInstructions()
Stack
Its purpose is to model
the Stack idea
void push(double value)
double pop()
58
CSD Univ. of Crete
Fall 2008
Example… gaining an understanding
example.stk
public class StackMachine{
push 5
ProgramLoader pl;
push 4
Stack stack;
subtract
public StackMachine(){
push 6
pl = new ProgramLoader();
multiply
stack = new Stack();
push 5
}
add
public void load(String fileName){
print
pl.load(fileName);
}
Client code
public void run(){
public static void main(String[] args){
String instruction;
StackMachine sm = new StackMachine();
for(int i=0; i<pl.
numInstructions(); i++){ sm.load(“example.stk”);
sm.run();
instruction = pl.get(i);
System.out.println(instruction); }
}
What happens here?
}
59
CSD Univ. of Crete
Fall 2008
Implementing the instructions: First Solution
public class StackMachine{
...
public void run(){
String instruction;
for(int i=0; i<pl.numInstructions(); i++){
instruction = pl.get(i);
StringTokenizer st = new StringTokenizer(instruction);
String command = st.nextToken();
if (command.toUpperCase(“PUSH”){
Messy,
String parameter = st.nextToken();
long,
stack.push(Double.parseDouble(parameter)); yuck, …
}
else if (command.toUpperCase(“PRINT”){
double d = stack.pop();
System.out.println(d);
}
...
}
}
60
Fall 2008
CSD Univ. of Crete
Implementing the instructions: Better Solution
Think of instruction as “classes” and group them
Organized by
number of parameters
instructions
pop
push
divide
add
subtract
multiply
one parameter
instruction
print
no parameter
instruction
Organized by function
arithmetic instructions
stack
instructions
push
pop
multiply
add divide
instructions
subtract
print
utility
instructions
61
Fall 2008
CSD Univ. of Crete
Implementing the instructions: Better Solution
Instruction
OneParameterInstruction
push
print
NoParameterInstruction
pop
add
multiply
divide
subtract
Instruction
StackInstruction
push
pop
ArithmeticInstruction
UtilityInstruction
add subtract divide multiply
print
 Each instruction will know how to “execute” itself
 Each instruction will know how to initialize itself
62
Fall 2008
CSD Univ. of Crete
Implementing the instructions: Better Solution
public class StackMachine{
...
public void run(){
String instruction;
for(int i=0; i<pl.numInstructions(); i++){
instruction = pl.get(i);
StringTokenizer st = new StringTokenizer(instruction);
String command = st.nextToken();
try{ Instruction instRef =
(Instruction) Class.forName(command)).newInstance();
instRef.load(st);
instRef.execute(stack); } catch(Exception e)
System.out.println(“Syntax error – bad instruction”);
Client code
System.exit(0);
}
public static void main(String[] args){
}
StackMachine sm = new StackMachine();
}
}
sm.load(“example.stk”);
sm.run();}
63
Fall 2008
CSD Univ. of Crete
Implementing the instructions: Better Solution
public interface Instruction{
public void load(StringTokenizer);
public void execute(Stack);
}
public abstract class ArithmeticInstruction implements Instruction{
public void load(StringTokenizer st){} }
public class Add extends ArithmeticInstruction{
public void execute(Stack stack){
double operand1 = stack.pop();
double operand2 = stack.pop();
stack.push(operand1+operand2);
}
}
64
Fall 2008
CSD Univ. of Crete
Implementing the instructions: Better Solution
public interface Instruction{
public void load(StringTokenizer);
public void execute(Stack);
}
public abstract class StackInstruction implements Instruction{
// only here for design completeness }
public class PopInstruction extends
StackInstruction{
public void load(StringTokenizer st){}
public void execute(Stack stack){
stack.pop(); public class PushInstruction extends StackInstruction{
double value;
}
public void load(StringTokenizer st){
}
String parameter = st.nextToken();
value = Double.parseDouble(parameter); }
public void execute(Stack stack){
stack.push(value); } }
65