ITS 320 Java Program 2 Custom BankAccount Class with a Modified Constructor

$ 15

ITS 320 Java Program 2 Custom BankAccount Class with a Modified Constructor

1) Enter the code for the two classes “BankAccount.java” and “Program2.java” shown below. The Program2 class is a driver for the BankAccount class. Note that this version of the BankAccount class accepts a monthly interest rate in decimal format which must be calculated by the user.
/**
* BankAccount class
* This class simulates a bank account.
*
* (Taken from “Starting Out with Java – Early Objects
* (Third Edition) by Tony Gaddis, 2008 by Pearson Educ.)
*
*/
public class BankAccount
{
private double balance; // Account balance
private double interestRate; // Interest rate
private double interest; // Interest earned

/**
* The constructor initializes the balance
* and interestRate fields with the values
* passed to startBalance and intRate. The
* interest field is assigned to 0.0.
*/
public BankAccount(double startBalance,
double intRate)
{
balance = startBalance;
interestRate = intRate;
interest = 0.0;
}

/**
* The deposit method adds the parameter
* amount to the balance field.
*/
public void deposit(double amount)
{
balance += amount;
}

/**
* The withdraw method subtracts the
* parameter amount from the balance
* field.
*/
public void withdraw(double amount)
{
balance -= amount;
}

/**
* The addInterest method adds the interest
* for the month to the balance field.
*/
public void addInterest()
{
interest = balance * interestRate;
balance += interest;
}

/**
* The getBalance method returns the
* value in the balance field.
*/
public double getBalance()
{
return balance;
}

/**
* The getInterest method returns the
* value in the interest field.
*/
public double getInterest()
{
return interest;
}
}

/**
*
* Colorado State University – ITS-320 – Basic Programming
*
* This program demonstrates the BankAccount class.
*
* (Taken from “Starting Out with Java – Early Objects
* (Third Edition) by Tony Gaddis, 2008 by Pearson Educ.)
*
* Programmed by: Reggie Haseltine, instructor
*
* Date: June 19, 2010
*
*/
import java.util.Scanner; // Needed for the Scanner class
import java.text.DecimalFormat; // Needed for 2 decimal place amounts
public class Program2 {
public static void main(String[] args)
{
BankAccount account; // To reference a BankAccount object
double balance, // The account’s starting balance
interestRate, // The annual interest rate
pay, // The user’s pay
cashNeeded; // The amount of cash to withdraw

// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);

// Create an object for dollars and cents
DecimalFormat formatter = new DecimalFormat (“#0.00”);

// Get the starting balance.
System.out.print(“What is your account’s ” + “starting balance? “);
balance = keyboard.nextDouble();

// Get the monthly interest rate.
System.out.print(“What is your monthly interest rate? “);
interestRate = keyboard.nextDouble();

// Create a BankAccount object.
account = new BankAccount(balance, interestRate);

// Get the amount of pay for the month.
System.out.print(“How much were you paid this month? “);
pay = keyboard.nextDouble();

// Deposit the user’s pay into the account.
System.out.println(“We will deposit your pay ” + “into your account.”);
account.deposit(pay);
System.out.println(“Your current balance is $” + formatter.format( account.getBalance() ));

// Withdraw some cash from the account.
System.out.print(“How much would you like ” + “to withdraw? “);
cashNeeded = keyboard.nextDouble();
account.withdraw(cashNeeded);

// Add the monthly interest to the account.
account.addInterest();

// Display the interest earned and the balance.
System.out.println(“This month you have earned $” + formatter.format( account.getInterest() ) + ” in interest.”);
System.out.println(“Now your balance is $” + formatter.format( account.getBalance() ) );
}
}

Compile the two test files (BankAccount.java first and then Program2.java second). Execute Program2 with the following inputs:
starting balance – $500 (don’t enter the dollar sign)
monthly interest rate – 0.00125 (this is a 1.5% annual rate)
monthly pay – $1000 (don’t enter the dollar sign)
withdrawal amount – $900 (don’t enter the dollar sign)
Verify that you earn $0.75 in interest and have an ending balance at the end of the month of $600.75.

Then modify the BankAccount class’s constructor method to create a BankAccount object which stores a monthly interest when the user inputs an annual interest rate of the format “nnn.nn” (i.e. 1.5). Note that the BankAccount constructor stored a monthly interest rate for the BankAccount object’s instance field originally, but the user had to convert the annual rate to a monthly rate (i.e. 1.5 to 0.00125). Then modify the Program2 driver class to prompt the user for an annual interest rate. Recompile both classes and execute the modified Program2 driver class again, this time with following inputs:
starting balance – $500 (don’t enter the dollar sign)
annual interest rate – 1.5
monthly pay – $1000 (don’t enter the dollar sign)
withdrawal amount – $900 (don’t enter the dollar sign)
Verify that you still earn $0.75 in interest and still have an ending balance at the end of the month of $600.75 as you did with the original code.

Submit only the modified source code files, final user inputs, and final output. Do not submit the original source code, inputs, and output.

Be sure that you include the course, the program number, your name, and the date in your program header. Also include this information at the top of your Microsoft Word file. Include additional comments as necessary and maintain consistent indentation for good programming style as shown and discussed in our text.

2) You may use the Windows Command Prompt command line interface or any Java IDE you choose to compile and execute your program.

3) You are to submit the following deliverables to the Dropbox:
a) A single Microsoft Word file containing a screen snapshot of your Java source code for both Program2.java and BankAccount.java (just the beginnings of the source code is OK) as it appears in your IDE (e.g. jGRASP, Net Beans, JDeveloper, etc.) or editor (e.g. a DOS “more” of the .java file’s first screen).
b) A listing of your entire modified version of the Java source code for Program2.java and BankAccount.java in the same Microsoft Word file as item a), and following item a).
You can simply copy and paste the text from your IDE into Word. Be sure to maintain proper code alignment by using Courier font for this item. Do not submit the original source code files! c) A screen snapshot showing all of your program’s inputs and output in the same Microsoft Word file, and following item b) above.

4) Your instructor may compile and run your program to verify that it compiles and executes properly.

5) You will be evaluated on (in order of importance):
a) Inclusion of all deliverables in Step #3 in a single Word file.
b) Correct execution of your program. This includes getting the correct results with the modified class files!
c) Adequate commenting of your code.
d) Good programming style (as shown and discussed in the textbook’s examples).
e) Neatness in packaging and labeling of your deliverables.

6) You must put all your screen snapshots and source code to a single Microsoft Word file.

67 in stock

SKU: ITS320P2 Category:

Description

ITS 320 Java Program 2 Custom BankAccount Class with a Modified Constructor

1) Enter the code for the two classes “BankAccount.java” and “Program2.java” shown below. The Program2 class is a driver for the BankAccount class. Note that this version of the BankAccount class accepts a monthly interest rate in decimal format which must be calculated by the user.
/**
* BankAccount class
* This class simulates a bank account.
*
* (Taken from “Starting Out with Java – Early Objects
* (Third Edition) by Tony Gaddis, 2008 by Pearson Educ.)
*
*/
public class BankAccount
{
private double balance; // Account balance
private double interestRate; // Interest rate
private double interest; // Interest earned

/**
* The constructor initializes the balance
* and interestRate fields with the values
* passed to startBalance and intRate. The
* interest field is assigned to 0.0.
*/
public BankAccount(double startBalance,
double intRate)
{
balance = startBalance;
interestRate = intRate;
interest = 0.0;
}

/**
* The deposit method adds the parameter
* amount to the balance field.
*/
public void deposit(double amount)
{
balance += amount;
}

/**
* The withdraw method subtracts the
* parameter amount from the balance
* field.
*/
public void withdraw(double amount)
{
balance -= amount;
}

/**
* The addInterest method adds the interest
* for the month to the balance field.
*/
public void addInterest()
{
interest = balance * interestRate;
balance += interest;
}

/**
* The getBalance method returns the
* value in the balance field.
*/
public double getBalance()
{
return balance;
}

/**
* The getInterest method returns the
* value in the interest field.
*/
public double getInterest()
{
return interest;
}
}

/**
*
* Colorado State University – ITS-320 – Basic Programming
*
* This program demonstrates the BankAccount class.
*
* (Taken from “Starting Out with Java – Early Objects
* (Third Edition) by Tony Gaddis, 2008 by Pearson Educ.)
*
* Programmed by: Reggie Haseltine, instructor
*
* Date: June 19, 2010
*
*/
import java.util.Scanner; // Needed for the Scanner class
import java.text.DecimalFormat; // Needed for 2 decimal place amounts
public class Program2 {
public static void main(String[] args)
{
BankAccount account; // To reference a BankAccount object
double balance, // The account’s starting balance
interestRate, // The annual interest rate
pay, // The user’s pay
cashNeeded; // The amount of cash to withdraw

// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);

// Create an object for dollars and cents
DecimalFormat formatter = new DecimalFormat (“#0.00”);

// Get the starting balance.
System.out.print(“What is your account’s ” + “starting balance? “);
balance = keyboard.nextDouble();

// Get the monthly interest rate.
System.out.print(“What is your monthly interest rate? “);
interestRate = keyboard.nextDouble();

// Create a BankAccount object.
account = new BankAccount(balance, interestRate);

// Get the amount of pay for the month.
System.out.print(“How much were you paid this month? “);
pay = keyboard.nextDouble();

// Deposit the user’s pay into the account.
System.out.println(“We will deposit your pay ” + “into your account.”);
account.deposit(pay);
System.out.println(“Your current balance is $” + formatter.format( account.getBalance() ));

// Withdraw some cash from the account.
System.out.print(“How much would you like ” + “to withdraw? “);
cashNeeded = keyboard.nextDouble();
account.withdraw(cashNeeded);

// Add the monthly interest to the account.
account.addInterest();

// Display the interest earned and the balance.
System.out.println(“This month you have earned $” + formatter.format( account.getInterest() ) + ” in interest.”);
System.out.println(“Now your balance is $” + formatter.format( account.getBalance() ) );
}
}

Compile the two test files (BankAccount.java first and then Program2.java second). Execute Program2 with the following inputs:
starting balance – $500 (don’t enter the dollar sign)
monthly interest rate – 0.00125 (this is a 1.5% annual rate)
monthly pay – $1000 (don’t enter the dollar sign)
withdrawal amount – $900 (don’t enter the dollar sign)
Verify that you earn $0.75 in interest and have an ending balance at the end of the month of $600.75.

Then modify the BankAccount class’s constructor method to create a BankAccount object which stores a monthly interest when the user inputs an annual interest rate of the format “nnn.nn” (i.e. 1.5). Note that the BankAccount constructor stored a monthly interest rate for the BankAccount object’s instance field originally, but the user had to convert the annual rate to a monthly rate (i.e. 1.5 to 0.00125). Then modify the Program2 driver class to prompt the user for an annual interest rate. Recompile both classes and execute the modified Program2 driver class again, this time with following inputs:
starting balance – $500 (don’t enter the dollar sign)
annual interest rate – 1.5
monthly pay – $1000 (don’t enter the dollar sign)
withdrawal amount – $900 (don’t enter the dollar sign)
Verify that you still earn $0.75 in interest and still have an ending balance at the end of the month of $600.75 as you did with the original code.

Submit only the modified source code files, final user inputs, and final output. Do not submit the original source code, inputs, and output.

Be sure that you include the course, the program number, your name, and the date in your program header. Also include this information at the top of your Microsoft Word file. Include additional comments as necessary and maintain consistent indentation for good programming style as shown and discussed in our text.

2) You may use the Windows Command Prompt command line interface or any Java IDE you choose to compile and execute your program.

3) You are to submit the following deliverables to the Dropbox:
a) A single Microsoft Word file containing a screen snapshot of your Java source code for both Program2.java and BankAccount.java (just the beginnings of the source code is OK) as it appears in your IDE (e.g. jGRASP, Net Beans, JDeveloper, etc.) or editor (e.g. a DOS “more” of the .java file’s first screen).
b) A listing of your entire modified version of the Java source code for Program2.java and BankAccount.java in the same Microsoft Word file as item a), and following item a).
You can simply copy and paste the text from your IDE into Word. Be sure to maintain proper code alignment by using Courier font for this item. Do not submit the original source code files! c) A screen snapshot showing all of your program’s inputs and output in the same Microsoft Word file, and following item b) above.

4) Your instructor may compile and run your program to verify that it compiles and executes properly.

5) You will be evaluated on (in order of importance):
a) Inclusion of all deliverables in Step #3 in a single Word file.
b) Correct execution of your program. This includes getting the correct results with the modified class files!
c) Adequate commenting of your code.
d) Good programming style (as shown and discussed in the textbook’s examples).
e) Neatness in packaging and labeling of your deliverables.

6) You must put all your screen snapshots and source code to a single Microsoft Word file.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.