6/4/01 Figure 1.1 Translating a high-level program
High-level
program
Processor
ABC program
(executable)
Compiler
6/4/01 Figure 1.2 Compiling and executing a Java program
Java Source Code
JVM
Byte code
Compiler
Interpreter for
Processor 1
Interpreter for
Processor 2
6/4/01
<applet code=HelloApplet.class width=300 height=200></applet>
Figure 1.4 An HTML file for the applet of Example 1.2
6/4/01
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
6/4/01
<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
6/4/01
Figure 1.14 A vending machine object
Coin
Change
SweetSweet
Candy Pretzels
Salty
Refund
6/4/01
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
6/4/01
Customer Waiter Cook
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
6/4/01
placeOrder takeOrder makeBurger pay serve makeFries
A customer A waiter A cook
Figure 1.17 Objects showing only available services
6/4/01 Figure 1.18 Scenario for a successful deposit
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. …
6/4/01
Accept an ATM cardAccept a PINAccept a transaction typeAccept an account typeAccept an amountAccept an account
Teller
Deposit an amountBankAccount
Find a specified accountBank
Specify a PINSelect a transaction typeSelect an account typeSpecify an amount
User
Figure 1.19 Responsibilities derived from the scenario of Figure 5.14
6/4/01 Figure 1.20 Implementing BankAccount state and behavior
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.
6/4/01 Figure 1.21 The BankAccount class
BankAccount
balance
getBalance
deposit
withdraw
6/4/01 Figure 1.22 Two BankAccount objects
myAccount:BankAccountbalance = 24.50
getBalance
deposit
withdraw
yourAccount:BankAccountbalance = 142.11
getBalance
deposit
withdraw