Modify the Account class from Chapter 4 so that it also permits an account to be opened with just a name and an account number, assuming an initial balance of zero. Modify the main method of the Transactions class to demonstrate this new capability.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Answer in Java pl

PP 7.1 Modify the Account class from Chapter 4 so that it also permits
an account to be opened with just a name and an account
number, assuming an initial balance of zero. Modify the main
method of the Transactions class to demonstrate this new
capability.
Transcribed Image Text:PP 7.1 Modify the Account class from Chapter 4 so that it also permits an account to be opened with just a name and an account number, assuming an initial balance of zero. Modify the main method of the Transactions class to demonstrate this new capability.
KX** X*** **
import java.text.NumberFormat;
public class Account
{
private final double RATE = 0.035;
// interest rate of 3.5%
private long acctNumber;
private double balance;
private String name;
//
Sets up the account by defining its owner, account number,
//
and initial balance.
public Account (String owner, long account, double initial)
{
name = owner;
acctNumber = account;
balance = initial;
}
//
//
//
//--
Deposits the specified amount into the account. Returns the
new balance.
public double deposit (double amount)
{
balance = balance + amount;
return balance;
}
//
Withdraws the specified amount from the account and applies
//
the fee. Returns the new balance.
/-
public double withdraw (double amount, double fee)
{
balance = balance - amount
return balance;
}
fee;
/-
// Adds interest to the account and returns the new balance.
/-
public double addInterest ()
{
balance += (balance * RATE);
return balance;
}
//
//
//--
Returns the current balance of the account.
public double getBalance ()
{
return balance;
}
//--
//
Returns a one-line description of the account as a string.
//--
public String toString ()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return (acctNumber + "\t" +
}
}
name + "\t" + fmt.format(balance));
/********* ********** ************************************* ************
public class Transactions
{
//-
//
Creates some bank accounts and requests various services.
//---
public static void main (String0 args)
{
Account acctl
= new Account ("Ted Murphy", 72354, 102.56);
Account acct2 = new Account ("Jane Smith", 69713, 40.00);
Account acct3 = new Account ("Edward Demsey", 93757, 759.32);
acctl.deposit (25.85);
double smithBalance = acct2.deposit (500.00);
System.out.println ("Smith balance after deposit:
smithBalance);
+
System.out.println ("Smith balance after withdrawal: "
acct2.withdraw (430.75, 1.50));
+
acctl.addInterest();
acct2.addInterest();
acct3.addInterest();
System.out.println ();
System.out.println (acct1);
System.out.println (acct2);
System.out.println (acct3);
Transcribed Image Text:KX** X*** ** import java.text.NumberFormat; public class Account { private final double RATE = 0.035; // interest rate of 3.5% private long acctNumber; private double balance; private String name; // Sets up the account by defining its owner, account number, // and initial balance. public Account (String owner, long account, double initial) { name = owner; acctNumber = account; balance = initial; } // // // //-- Deposits the specified amount into the account. Returns the new balance. public double deposit (double amount) { balance = balance + amount; return balance; } // Withdraws the specified amount from the account and applies // the fee. Returns the new balance. /- public double withdraw (double amount, double fee) { balance = balance - amount return balance; } fee; /- // Adds interest to the account and returns the new balance. /- public double addInterest () { balance += (balance * RATE); return balance; } // // //-- Returns the current balance of the account. public double getBalance () { return balance; } //-- // Returns a one-line description of the account as a string. //-- public String toString () { NumberFormat fmt = NumberFormat.getCurrencyInstance(); return (acctNumber + "\t" + } } name + "\t" + fmt.format(balance)); /********* ********** ************************************* ************ public class Transactions { //- // Creates some bank accounts and requests various services. //--- public static void main (String0 args) { Account acctl = new Account ("Ted Murphy", 72354, 102.56); Account acct2 = new Account ("Jane Smith", 69713, 40.00); Account acct3 = new Account ("Edward Demsey", 93757, 759.32); acctl.deposit (25.85); double smithBalance = acct2.deposit (500.00); System.out.println ("Smith balance after deposit: smithBalance); + System.out.println ("Smith balance after withdrawal: " acct2.withdraw (430.75, 1.50)); + acctl.addInterest(); acct2.addInterest(); acct3.addInterest(); System.out.println (); System.out.println (acct1); System.out.println (acct2); System.out.println (acct3);
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY