Question

(JAVA NetBeans)

Write programs in java

3. Write a Java program having a class StudentAccount which extends CheckingAccount. StudentAccount has its own new fields an

Modify the textbook example

textbook example:

//BankAccount.java

import java.text.DecimalFormat;

public class BankAccount
{
public final DecimalFormat MONEY
= new DecimalFormat( "$#,##0.00" );
private double balance;

/** Default constructor
* sets balance to 0.0
*/
public BankAccount( )
{
balance = 0.0;
System.out.println( "In BankAccount default constructor" );
}

/** Overloaded constructor
* @param startBalance beginning balance
*/
public BankAccount( double startBalance )
{
if ( balance >= 0.0 )
balance = startBalance;
else
balance = 0.0;
System.out.println( "In BankAccount overloaded constructor" );
}

/** toString
* @return the balance formatted as money
*/
public String toString( )
{
return ( "balance is " + MONEY.format( balance ) );
}
}

============================================================================

//CheckingAccount.java

public class CheckingAccount extends BankAccount
{
/** default constructor
* explicitly calls the BankAccount default constructor
*/
public CheckingAccount( )
{
super( ); // optional, call BankAccount constructor
System.out.println( "In CheckingAccount "
+ "default constructor" );
}

/** overloaded constructor
* calls BankAccount overloaded constructor
* @param startBalance starting balance
*/
public CheckingAccount( double startBalance )
{
super( startBalance ); // call BankAccount constructor
System.out.println( "In CheckingAccount "
+ "overloaded constructor" );
}
}

============================================================================

//CheckingAccountClient.java

public class CheckingAccountClient
{
public static void main( String [] args )
{
// use default constructor
CheckingAccount c1 = new CheckingAccount( );
System.out.println( "New checking account: " + c1 + "\n" );

// use overloaded constructor
CheckingAccount c2 = new CheckingAccount( 100.00 );
System.out.println( "New checking account: " + c2 );
}
}

Examples 10.4, 10.5, and 10.6 BankAccount.java 1/* CheckingAccount Client, version 2 DCheckingAccount.java CheckingAccountCli


Modify the bank account and checking account of the textbook and plus one class stundent account
3. Write a Java program having a class StudentAccount which extends CheckingAccount. StudentAccount has its own new fields and methods.
Examples 10.4, 10.5, and 10.6 BankAccount.java 1/* CheckingAccount Client, version 2 DCheckingAccount.java CheckingAccountClientjava Anderson, Franceschi 2 3 */ 4 5 public class CheckingAccountClient 6 C public static void main String 7e args { / use default constructor 10 CheckingAccount cl = new CheckingAccount ; System.out.println "New checking account: " c1 +"\n" ) ; 11 12 / use overloaded constructor CheckingAccount c2 new CheckingAccount 100.00); System.out.println "New checking account: "c2) 13 14 15 16 17 In BankAccount default constructor In CheckingAccount de fault constructor New checking account: balance is $0.00 In BankAccount overloaded constructor In CheckingAccount overloaded constructor New checking account: balance is $100.00 24 t Publishers, Inc. (www.jbpub.com)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
here we applied some login about account type which is part of student account
if initial balance is o then account is student type, otherwise it is saving type

also here we added some override method like add and withdraw that adjusted by super keyword
*/
package printerjob;

import java.text.DecimalFormat;

class StudentAccount
{
public final DecimalFormat MONEY
= new DecimalFormat( "$#,##0.00" );
private double balance;
private String accountype;

/** Default constructor
* sets balance to 0.0
*/
public StudentAccount( )
{
balance = 0.0;
accountype="StudentsAcc";
System.out.println( "In BankAccount default constructor" );
}
public void addbalance(int amount){
    balance=balance+amount;
    System.out.println("Newely Updated balance is "+balance);
}
public void withdraw(int amount){
    if(balance-amount<0)
        System.out.println("Invalid Withdraw");
    else
        System.out.println("After Withdraw newly balance is "+amount);
}

/** Overloaded constructor
* @param startBalance beginning balance
*/
public StudentAccount( double startBalance )
{
if ( balance >= 0.0 ){
balance = startBalance;
accountype="SavingAcc";
}
else
balance = 0.0;
System.out.println( "In BankAccount overloaded constructor" );
}

/** toString
* @return the balance formatted as money
*/
public String toString( )
{
return ( "balance is " + MONEY.format( balance )+" Account Type is "+accountype);
}
}


//CheckingAccount.java
//checkingTrascationn is count for transaction done by users
class CheckingAccount extends StudentAccount
{
int checkingTrascation=0;
public CheckingAccount( )
{
super( ); // optional, call BankAccount constructor
checkingTrascation++;
System.out.println( "In CheckingAccount "
+ "default constructor" );
    System.out.println("Transaction "+checkingTrascation+" Completed");
}

/** overloaded constructor
* calls BankAccount overloaded constructor
* @param startBalance starting balance
*/
public CheckingAccount( double startBalance )
{
super( startBalance ); // call BankAccount constructor
System.out.println( "In CheckingAccount "
+ "overloaded constructor" );
checkingTrascation++;
System.out.println("Transaction "+checkingTrascation+" Completed");
}

public void addbalance(int amount){
    // calling method from students account class override
    super.addbalance(amount);
    checkingTrascation++;
    System.out.println("Transaction "+checkingTrascation+" Completed");
}
public void withdraw(int amount){
    // calling method from students account class override
    super.withdraw(amount);
    checkingTrascation++;
    System.out.println("Transaction "+checkingTrascation+" Completed");
}

}

//CheckingAccountClient.java

public class CheckingAccountStudents
{
public static void main( String [] args )
{
// use default constructor
CheckingAccount c1 = new CheckingAccount( );
System.out.println( "New checking account: " + c1 + "\n" );

c1.addbalance(200);
    System.out.println("");
c1.withdraw(100);
    System.out.println("");


    System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");


// use overloaded constructor
CheckingAccount c2 = new CheckingAccount( 100.00 );
System.out.println( "New checking account: " + c2 );
c2.addbalance(200);
    System.out.println("");
c2.withdraw(1000);
    System.out.println("");
}
}

/*

output

In BankAccount default constructor
In CheckingAccount default constructor
Transaction 1 Completed
New checking account: balance is $0.00 Account Type is StudentsAcc

Newely Updated balance is 200.0
Transaction 2 Completed

After Withdraw newly balance is 100
Transaction 3 Completed

+++++++++++++++++++++++++++++++++++++++++++++++++++++
In BankAccount overloaded constructor
In CheckingAccount overloaded constructor
Transaction 1 Completed
New checking account: balance is $100.00 Account Type is SavingAcc
Newely Updated balance is 300.0
Transaction 2 Completed

Invalid Withdraw
Transaction 3 Completed

*/

Add a comment
Know the answer?
Add Answer to:
(JAVA NetBeans) Write programs in java Modify the textbook example textbook example: //BankAccount.java import java.tex...
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
  • (JAVA NetBeans) Write programs in java Example 9.13~9.15 //Book.Java public class Book { private String title; private...

    (JAVA NetBeans) Write programs in java Example 9.13~9.15 //Book.Java public class Book { private String title; private String author; private double price; /** * default constructor */ public Book() { title = ""; author = ""; price = 0.0; } /** * overloaded constructor * * @param newTitle the value to assign to title * @param newAuthor the value to assign to author * @param newPrice the value to assign to price */ public Book(String newTitle, String newAuthor, double newPrice)...

  • 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...

  • need basic default constructor , and shoed an example too s0. write the class Battery and...

    need basic default constructor , and shoed an example too s0. write the class Battery and it has s1. a data for the battery capacity (that is similar to myBalance of the BankAccount class.) s2. a parameterized constructor: public Battery(double amount) s3. a drain mutator s4. a change mutator s5. a getRemainingCapacity accessor Need to run this tester - public class BatteryTester{ public static void main(String[] args) { Battery autoBattery = new Battery(2000); //call default constructor System.out.println("1. battery capacity is...

  • What is the output of running class C? The three Java classes are in separate Java...

    What is the output of running class C? The three Java classes are in separate Java files in the same directory (or in the same package). class A { public AO { System.out.println("The default constructor of A"); } // end A constructor } // end class A class B extends A { public BCString s) { System.out.println(s); } // end B constructor } // end class B public class C { public static void main(String[] args) { B b =...

  • 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...

  • (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */...

    (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */ import java.awt.Graphics; public abstract class Animal { private int x; // x position private int y; // y position private String ID; // animal ID /** default constructor * Sets ID to empty String */ public Animal( ) { ID = ""; } /** Constructor * @param rID Animal ID * @param rX x position * @param rY y position */ public Animal( String...

  • Requirements:  Your Java class names must follow the names specified above. Note that they are...

    Requirements:  Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below.  BankAccount: an abstract class.  SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...

  • /* * To change this license header, choose License Headers in Project Properties. * To change...

    /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package checkingaccounttest; // Chapter 9 Part II Solution public class CheckingAccountTest { public static void main(String[] args) {    CheckingAccount c1 = new CheckingAccount(879101,3000); c1.deposit(350); c1.deposit(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.withdraw(350); c1.withdraw(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.deposit(1000); System.out.println(c1); System.out.println("After calling computeMonthlyFee()"); c1.computeMonthlyFee(); System.out.println(c1); } } class BankAccount { private int...

  • How would I alter this code to have the output to show the exceptions for not...

    How would I alter this code to have the output to show the exceptions for not just the negative starting balance and negative interest rate but a negative deposit as well? Here is the class code for BankAccount: /** * This class simulates a bank account. */ 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...

  • Write a unit test to test the following class. Using Java : //Test only the debit...

    Write a unit test to test the following class. Using Java : //Test only the debit method in the BankAccount. : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; } public String getCustomerName() { return customerName; } public double getBalance() { return balance; } public void setDebit(double amount) throws Exception { if (frozen) { throw...

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