Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using GUI to write out deposit withdraw,and intrest and get a balance at the end. Be able to login and login out. Plus be able
Using GUI to write out deposit withdraw,and intrest and get a balance at the end. Be able to login and login out. Plus be able to open an Account and closing an Account. as well as adding a Account.
use the program below using Java
Main
package com.company; import java.util.Scanner; public class Main { public static void main(String[] args) { // write your code here Accounts account = new Accounts(); Scanner input = new Scanner(System.in); System.out.print("Enter account number: "); account.setAccount_number(Integer.parseInt(input.nextLine())); System.out.print("Enter initial balance: "); account.setbalance(Integer.parseInt(input.nextLine())); System.out.print("Enter account type: "); account.settype(input.nextLine()); String choice = ""; while(true) { int amount; System.out.println("****** MENU ******"); System.out.println("(D)eposit"); System.out.println("(W)ithdraw "); System.out.println("(A)dd Interest"); System.out.println("(Q)uit"); System.out.print("Enter your choice: "); choice = input.nextLine(); if(choice.equalsIgnoreCase("D")) { System.out.print("Enter amount to deposit: "); amount = Integer.parseInt(input.nextLine()); if(amount < 0) { System.out.println("Invalid amount to deposit! "); continue; } account.deposit(amount); continue; } if(choice.equalsIgnoreCase("W")) { System.out.print("Enter amount to withdraw: "); amount = Integer.parseInt(input.nextLine()); if(amount < 0) { System.out.println("Invalid amount to withdraw! "); continue; } account.withdraw(amount); continue; } if(choice.equalsIgnoreCase("A")) { System.out.print("Enter interest amount to add: "); amount = Integer.parseInt(input.nextLine()); account.setintrest(amount); continue; } if(choice.equalsIgnoreCase("Q")) { break; } System.out.println("Invalid Input!"); System.out.println("Please try again"); continue; } System.out.println("Account information."); System.out.println(account); System.out.println(" Have a nice day!"); System.out.println("GoodBye."); } }
Accounts
package com.company; public class Accounts { private int Account_number; private int balance; private String type; private int intrest; Accounts(){ Account_number=0; balance =0; type = null; intrest=0; } Accounts(int Account_number,int balance,String type,int intrest){ setAccount_number(Account_number); setbalance(balance); settype(type); setintrest(intrest); } // set getters and setters public void setintrest(int intrest){ this.intrest=intrest; balance += this.intrest; } public void settype(String type) { this.type = type; } public void setbalance(int balance){ this.balance=balance; } public void setAccount_number(int Account_number){ this.Account_number=Account_number; } public int getAccount_number(){ return Account_number; } public int getbalance(){ return balance; } public String gettype(){ return type; } public int getintrest(){ return intrest; } public void deposit(int amount) { balance += amount; System.out.println("Amount deposited successfully."); System.out.println("Final Account balance after deposit is: "+getbalance()); } public void withdraw(int amount) { if(getbalance() >= amount) { balance -= amount; System.out.println("Amount withdrawn successfully."); System.out.println("Final Account balance after withdraw is: "+getbalance()); } else { System.out.println(">>>Insufficient funds in the account to process the withdraw<<<"); } } @Override public String toString() { return " [Account_number=" + Account_number + ", balance=" + balance + ", type=" + type + ", intrest=" + intrest + "]"; } }
Step 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