Sunteți pe pagina 1din 2

3URMHFW2YHUGUDZQDWWKH%DQN.

H\

Answers 15-7

import java.io.*;
import java.util.*;
public class 7HVWHU
{
public static void main(String args[])
{
Scanner kbReader = new Scanner(System.in);
System.out.print("Please enter the name to whom the account belongs. ");
String name = kbReader.nextLine( );
System.out.print("Please enter the amount of the deposit. ");
double amount = kbReader.nextDouble( );
BankAccount myAccount = new BankAccount(name, amount);
myAccount.deposit(505.22);
System.out.println(myAccount.balance);
myAccount.withdraw(100.00);
System.out.println("The " + myAccount.name + " account balance is, $" +
myAccount.balance);
}
}

public class %DQN$FFRXQW


{
public BankAccount(String nm, double amt)
{
name = nm;
balance = amt;
}
public void deposit(double dp)
{
balance = balance + dp;
}
public void withdraw(double wd)
{
balance = balance - wd;
}
public String name;
public double balance;
}

Answers 15-8

The screen output will appear as follows:


Please enter the name to whom the account belongs. Sally Jones
Please enter the amount of the deposit. 1000
The Sally Jones account balance is, $1405.2200012207031
You may be alarmed at the excessive number of decimal places in $1405.22000122. Dont worry
about it for now. We will learn how to handle this later.

S-ar putea să vă placă și