140 likes | 150 Views
High-level program. Processor ABC program (executable). Compiler. Figure 1.1 Translating a high-level program. Interpreter for Processor 1. Java Source Code. JVM Byte code. Compiler. Interpreter for Processor 2. Figure 1.2 Compiling and executing a Java program.
E N D
High-level program Processor ABC program (executable) Compiler Figure 1.1 Translating a high-level program
Interpreter for Processor 1 Java Source Code JVM Byte code Compiler Interpreter for Processor 2 Figure 1.2 Compiling and executing a Java program
<applet code=HelloApplet.class width=300 height=200> </applet> Figure 1.4 An HTML file for the applet of Example 1.2
Get the ingredients. Get the cookware needed. Crack the eggs into a bowl. Add salt. Beat the eggs. Melt some butter in the frying pan. Pour the eggs into the frying pan. Turn the eggs over. Add the cheese, folding the eggs over. Serve the omelet. Clean up. Figure 1.9 The “program” for preparing an omelet
<title> A First Look At Everything </title> <h2> Art’s bank has two customers <br> </h2> <h3> John Venn with PIN 123123123 <br> Mabel Venn with PIN 456456456 </h3><p> <ul> <li> Press the <em>Start</em> button to start. <li> The ATM prompts each step with a message. <li> Enter one of the two user names to begin transactions. <li> Hit the Enter key when done. <li> No new accounts or users can be created. <li> Press the Finish button when the current user is done. <li> Press the Start button to enter another user name. <p> <applet code=AtmScreen.class width=400 height=200> </applet> Figure 1.12 The HTML file used to run Example 1.5
The customer orders a burger, soda, and fries from the waiter. The waiter asks the cook to make a burger. The waiter serves the soda to the customer. The waiter asks the cook to make the fries. The cook gives the waiter the burger to serve. The cook gives the waiter the fries to serve. The waiter asks the customer to pay. Figure 1.15 A scenario for a fast food order
CustomerWaiterCook State money cash burgers and fries Responsibilities place an order take an order make burgers pay serve an item make fries Figure 1.16 State and responsibilities for Customer, Waiter, and Cook
placeOrder takeOrder makeBurger pay serve makeFries A customer A waiter A cook Figure 1.17 Objects showing only available services
The user asks the teller to accept an ATM card. The teller asks the user to enter a PIN. The user asks the teller to accept a PIN. The teller asks the user to select a transaction type. The user asks the teller to accept a deposit. The teller asks the user to select an account type. The user asks the teller to accept a savings account type. The teller asks the bank to find the account of the chosen type for the user with the specified PIN. The bank gives the teller a reference to the account. The teller asks the user to specify an amount. The user asks the teller to accept an amount. The teller asks the account to deposit the specified amount. The teller asks the user to select another transaction. … Figure 1.18 Scenario for a successful deposit
User Specify a PIN Select a transaction type Select an account type Specify an amount Bank Find a specified account BankAccount Deposit an amount Teller Accept an ATM card Accept a PIN Accept a transaction type Accept an account type Accept an amount Accept an account Figure 1.19 Responsibilities derived from the scenario of Figure 5.14
balance A decimal value representing the dollar amount of the current balance for that account. deposit an amount Add the amount to the current balance. withdraw an amount It the amount is not greater than the current balance, subtract the amount from the current balance. getBalance Get the current balance. Figure 1.20 Implementing BankAccount state and behavior
BankAccount balance getBalance deposit withdraw Figure 1.21 The BankAccount class
myAccount:BankAccount yourAccount:BankAccount balance = 24.50 balance = 142.11 getBalance deposit withdraw getBalance deposit withdraw Figure 1.22 Two BankAccount objects