public class TestInterface
1: //TestInterface.java
2: //Simple demo of interface use
4: import java.io.*;
7: public class TestInterface
8: {
9: static BufferedReader keyboard =
10: new BufferedReader(new InputStreamReader(System.in));
11: static PrintWriter screen =
12: new PrintWriter(System.out, true);
14: public static void pause() throws IOException
15: {
16: screen.print("Press ENTER to continue ... ");
17: screen.flush();
18: keyboard.readLine();
19: }
22: static void displayGrossWage(NameAndPayInterface person)
23: {
24: screen.println(person.getName() + " earns $" +
25: person.getGrossWage() + " per week.");
26: }
29: public static void main(String[] args) throws IOException
30: {
31: WorkerWithIFace janitor = new WorkerWithIFace("Fred");
32: janitor.setHoursWorked(35.0f);
33: janitor.setRateOfPay(10.25f);
35: ExecutiveWithIFace director = new ExecutiveWithIFace("Clive");
36: director.setAnnualSalary(48108.0f);
39: //Direct access to member functions for each class object:
40: screen.println();
41: screen.println(janitor.getName() + " earns $" +
42: janitor.getGrossWage() + " per week.");
43: screen.println(director.getName() + " earns $" +
44: director.getGrossWage() + " per week.");
45: pause();
48: //Compare these actual parameters with formal parameter above:
49: screen.println();
50: displayGrossWage(janitor);
51: displayGrossWage(director);
52: pause();
53: }
54: }