Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Submission 3: Should we allow the negative as the input, if not, please modify the code to guarantee that there is no negative input. Print
Submission 3: Should we allow the negative as the input, if not, please modify the code to guarantee that there is no negative input. Print Debit amount cannot be negative." Add the same condition for deposit() and test it. (PLEASE ANSER TO THIS IS VERY IMPORTANT) Thank you for your time.
1/ Account.java // Account class with a constructor to // initialize instance variable balance. public class Account private double balance; // instance variable that stores the balance // *** To do 1. Add another instance variable that stores the account number // constructor (*** To do 2. Need to initialize account number) public Account ( double initialBalance ) // if initialBalance is not greater than 0.0, // balance is still initialized to 0.0 by default if ( initial Balance > 0.0 ) balance = initialBalance; } // end Account constructor // credits (adds) an amount to the account public void credit ( double amount ) balance = balance + amount; // add amount to balance } // end method credit // ***To do 3. debits (subtracts) an amount from the account // returns the account balance public double getBalance () // **** To do 4. add a print-out return balance; // gives the value of balance to the calling method } // end method getBalance } // end class Account // Create and manipulate an Account object. import java.util.Scanner; public class Account Test // main method begins execution of Java application public static void main(String args[]) Account accountl = new Account ( 1, 50.00 ); // create Account object Account account2 = new Account ( 2, -7.53 ); // create Account object // display initial balance of each object accounti.getBalance(); account2.getBalance(); // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); double depositAmount; // deposit amount read from user System.out.print("Enter deposit amount for account2: "); depositAmount = input.nextDouble(); // obtain user input System.out.printf(" adding $.2f from account2 balance ", depositAmount ); account2.credit ( deposit Amount ); // add amount to account2 // display balances accounti.getBalance (); account2.getBalance (); // create Scanner to obtain input from command window input = new Scanner(System.in); double withdrawalAmount; // withdrawal amount read from user System.out.print("Enter withdrawal amount for accounti: withdrawal Amount = input.nextDouble(); // obtain user input System.out.printf(" subtracting $.2f from accounti balance withdrawalAmount ); accountl.debit( withdrawalAmount ); // subtract amount from accounti // display balances accountl.getBalance(); account2.getBalance (); } // end main } // end class Account Test Description of the Problem: Modify class Account (attached in Blackboard) to provide An integer class instant variable accountNum to be the class number (Don't forget that you need to change the constructor). A method called debit that withdraws money from an Account. Ensure that the debit amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the method should print a message indicating Debit amount exceeded account balance. In method getBalance (), add a line to print out the account number and account balance, then in the Test program, you just need to type, accountl.getBalance(); instead of the printf statement. AccountTest file has been modified already to test your new Account class, so you do not need to change it. 1/ Account.java // Account class with a constructor to // initialize instance variable balance. public class Account private double balance; // instance variable that stores the balance // *** To do 1. Add another instance variable that stores the account number // constructor (*** To do 2. Need to initialize account number) public Account ( double initialBalance ) // if initialBalance is not greater than 0.0, // balance is still initialized to 0.0 by default if ( initial Balance > 0.0 ) balance = initialBalance; } // end Account constructor // credits (adds) an amount to the account public void credit ( double amount ) balance = balance + amount; // add amount to balance } // end method credit // ***To do 3. debits (subtracts) an amount from the account // returns the account balance public double getBalance () // **** To do 4. add a print-out return balance; // gives the value of balance to the calling method } // end method getBalance } // end class Account // Create and manipulate an Account object. import java.util.Scanner; public class Account Test // main method begins execution of Java application public static void main(String args[]) Account accountl = new Account ( 1, 50.00 ); // create Account object Account account2 = new Account ( 2, -7.53 ); // create Account object // display initial balance of each object accounti.getBalance(); account2.getBalance(); // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); double depositAmount; // deposit amount read from user System.out.print("Enter deposit amount for account2: "); depositAmount = input.nextDouble(); // obtain user input System.out.printf(" adding $.2f from account2 balance ", depositAmount ); account2.credit ( deposit Amount ); // add amount to account2 // display balances accounti.getBalance (); account2.getBalance (); // create Scanner to obtain input from command window input = new Scanner(System.in); double withdrawalAmount; // withdrawal amount read from user System.out.print("Enter withdrawal amount for accounti: withdrawal Amount = input.nextDouble(); // obtain user input System.out.printf(" subtracting $.2f from accounti balance withdrawalAmount ); accountl.debit( withdrawalAmount ); // subtract amount from accounti // display balances accountl.getBalance(); account2.getBalance (); } // end main } // end class Account Test Description of the Problem: Modify class Account (attached in Blackboard) to provide An integer class instant variable accountNum to be the class number (Don't forget that you need to change the constructor). A method called debit that withdraws money from an Account. Ensure that the debit amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the method should print a message indicating Debit amount exceeded account balance. In method getBalance (), add a line to print out the account number and account balance, then in the Test program, you just need to type, accountl.getBalance(); instead of the printf statement. AccountTest file has been modified already to test your new Account class, so you do not need to change itStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started