Question

•create a new savings account object (for choice 2).

•ask the user to enter an initial balance which should be greater than 50. If the entered amount is less than 50, the program will ask the user to enter another amount. This continues until an amount greater than 50 is entered.

•Set the balance of the savings account object by calling the setBalance() method.

•Ask the user to deposit an amount. Deposit that amount and display the balance of the account.

CSC 2310 Homework HW 6 and Lab program will ask the user to enter another amount. This continues until an amount greater than 50 is entered Dr. Xiaolin Hu Set the balance of the savings account object by calling the HW6 & Lab: setBalance() method Ask the user to deposit an amount. Deposit that amount and display the balance of the account. Objective Lab: To learn basic inheritance using simple super class and sub class HW: To learn inheritance using graphics Part I:( Lab Programming) Due bv: End of Lab Turn in the SavingsAccount.java and testAccount.java Below is an illustration of how the program works: Welcome. Which account do you want to create? . You are given the class Account with predefined methods for bank account. It already has methods to display the balance and methods to withdraw and deposit some amount 2. Savings 1. Normal Enter choice: 2 Enter initial balance: (〉$50) -20 Balance should be greater than 50 Enter initial balance: (〉$50) -70 Balance 70.0 Enter amount to deposit: 100 Balance - 180.0 . You need to create a subclass called SavingsAccount. Your SavingsAccount class should override the deposit method, so that when a user deposits an amount in the savings account, the bank will add additional 10% to the amount . You are given a testAccount class which asks the user what account it want to create. In the testAccount class, add java code to do the following things in a sequential order: create a new savings account object (for choice 2) Part II: HW6 . ask the user to enter an initial balance which should be Deadlines as posted in d2l file Deadlines greater than 50. If the entered amount is less than 50, the

/**
* Super class Account
*
*/
public class Account {
   /**
   * balance of the account
   */
   protected double balance;
   /**
   * constructor
   */
   public Account() {
       balance = 0;
   }
   /**
   * set the balance
   * @param amt balance
   */
   public void setBalance(double amt) {
       balance += amt;
   }
   /**
   * deposit to account
   * @param amt
   */

   public void deposit(double amt) {
       balance += amt;
   }
   /**
   * withdraw from account
   * @param amt
   */

   public void withDraw(double amt) {
       balance -= amt;
   }

   /**
   * display the account balance
   */
   public void displayBalance() {
       System.out.println("Balance - " + balance);
   }
}

----------------------------------------

import java.util.Scanner;

public class testAccount {

   /**
   * A simple test function to test Account and SavingsAccount class
   * @param args
   */
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Welcome. Which account do you want to create? \n 1. Normal \t 2. Savings");
       System.out.print("Enter choice: ");
       int choice = sc.nextInt();
       Account acct = null;
       if (choice == 1) {
           acct = new Account();
           System.out.println("New normal account created.");
           acct.displayBalance();
       } else if (choice == 2) {
           //Here write your code as required in the Question          

       }
       //Deposit money to account here
       acct.displayBalance();

   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package mani;
import java.util.Scanner;
public class testAccount {
/**
* A simple test function to test Account and SavingsAccount class
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome. Which account do you want to create? \n 1. Normal \t 2. Savings");
System.out.print("Enter choice: ");
int choice = sc.nextInt();
double iBal;
Account acct = null;
if (choice == 1) {
acct = new Account();
System.out.println("New normal account created.");
acct.displayBalance();
} else if (choice == 2) {
   acct=new SavingsAccount();
   System.out.println("New savings account created.");
   while(true){
       System.out.print("Enter initial balance: (>$50) - ");
       iBal=sc.nextDouble();
       if(iBal<50){
           System.out.println("Balance should be greater than 50");
       }else{
           acct.setBalance(iBal);
           break;
       }
       acct.displayBalance();
   }
   System.out.print("Enter amount to deposit: ");
   double bal=sc.nextDouble();
   acct.deposit(bal);
//Here write your code as required in the Question
}
  
acct.displayBalance();
}
}

package mani;
public class Account {
/**
* balance of the account
*/
protected double balance;
/**
* constructor
*/
public Account() {
balance = 0;
}
/**
* set the balance
* @param amt balance
*/
public void setBalance(double amt) {
balance += amt;
}
/**
* deposit to account
* @param amt
*/
public void deposit(double amt) {
balance += amt;
}
/**
* withdraw from account
* @param amt
*/
public void withDraw(double amt) {
balance -= amt;
}
/**
* display the account balance
*/
public void displayBalance() {
System.out.println("Balance - " + balance);
}
}

package mani;

public class SavingsAccount extends Account {
public void deposit(double amt){
   balance+=amt;
   balance+=(amt*0.1);
}
  
  
}

Add a comment
Know the answer?
Add Answer to:
•create a new savings account object (for choice 2). •ask the user to enter an initial...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending...

    Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account. --->Console Welcome to the Account application Starting Balances Checking: $1,000.00 Savings:  $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee:              $1.00 Savings...

  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • If I enter a negative value the program throws an error and the withdrawal amount is...

    If I enter a negative value the program throws an error and the withdrawal amount is added to the balance please help me find why? public abstract class BankAccount { private double balance; private int numOfDeposits; private int numOfwithdrawals; private double apr; private double serviceCharge; //Create getter and setter methods public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public int getNumOfDeposits() { return numOfDeposits; } public void setNumOfDeposits(int numOfDeposits) { this.numOfDeposits =...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems....

    Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems. You have to do both of your java codes based on the two provided Java codes. Create one method for depositing and one for withdrawing. The deposit method should have one parameter to indicate the amount to be deposited. You must make sure the amount to be deposited is positive. The withdraw method should have one parameter to indicate the amount to be withdrawn...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate...

    solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...

  • Hello, I'm very new to programming and I'm running into a problem with the system.out.println function...

    Hello, I'm very new to programming and I'm running into a problem with the system.out.println function in the TestAccount Class pasted below. Account Class: import java.util.Date; public class Account {    private int accountId;    private double accountBalance, annualInterestRate;    private Date dateCreated;    public Account(int id, double balance) { id = accountId;        balance = accountBalance; dateCreated = new Date();    }    public Account() { dateCreated = new Date();    }    public int getId() { return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT