[Solved]Java Coding Help Need Use Case Statements M Sure Interest Correctly Someone Could Edit Cod Q37264453
JAVA coding HELP! I need to use case statements, but I’m not toosure If I did it for interest correctly. If someone could edit thecode for interest for case statements, it would help a lot(especially interest)! The code works, but needs to be in rightform of case statement.
What I’m suppose to do
Write a basic account management program that interacts with theuser as follows
Display a menu with 4 options
1) Deposit money
2) Withdraw money
3) Show current balance
4) Project investment
5) Exit
Enter option:
The user enters an option number from 1-5
Based on the user option selected, a follow up action occurs asdescribed on the next page – when that action is done, the programgoes back to the main menu for another user action
If option 5 is selected, the program ends
My code
import java.util.Scanner;
public static void main(String[] args) {
BankAccount obj1 = new BankAccount(“XYZ”,”BLAAAAAAH01″);
obj1.showMenu();}
}
class BankAccount
{
double balance;
int previousTransaction;
String customerName;
String customerId;
double rate;
int years;
double yearlyRate;
double total;
double balances;
BankAccount(String cname,String cid)
{
customerName = cname;
customerId = cid;
}
void deposit(int amount)
{
if(amount !=0)
{
balance = balance + amount;
previousTransaction = amount;
}
}
void withdraw(int amount)
{
if(amount !=0)
{
balance = balance – amount;
previousTransaction = -amount;
}
}
void Interest(double amount)
{
if(amount !=0)
{
total = balance + years * rate;
}
}
void getPreviousTransaction()
{
if(previousTransaction > 0)
{
System.out.println(“Deposisted: “+previousTransaction);
}
else if(previousTransaction < 0)
{
System.out.println(“withdrawn:”+Math.abs(previousTransaction));
}
else
{
System.out.println(“No transaction occured”);
}
}
void showMenu()
{
char option=”;
Scanner scanner = new Scanner(System.in);
System.out.println(“Welcome “+customerName);
System.out.println(“Your ID is “+customerId);
System.out.println(“n”);
System.out.println(“1. Check Balance”);
System.out.println(“2. Deposit”);
System.out.println(“3. Withdraw”);
System.out.println(“4. Previous Transaction”);
System.out.println(“5. Investment”);
System.out.println(“6. Exit”);
do
{
System.out.println(“=================================”);
System.out.println(“Enter an option”);
System.out.println(“=================================”);
option = scanner.next().charAt(0);
System.out.println(“n”);
switch(option)
{
case ‘1’:
System.out.println(“————————-“);
System.out.println(“Balance = “+balance);
System.out.println(“————————-“);
System.out.println(“n”);
break;
case ‘2’:
System.out.println(“————————-“);
System.out.println(“Enter an amount to deposit:”);
System.out.println(“————————-“);
int amount = scanner.nextInt();
deposit(amount);
System.out.println(“n”);
break;
case ‘3’:
System.out.println(“————————-“);
System.out.println(“Enter an amount to wirthdraw:”);
System.out.println(“————————-“);
int amount2 = scanner.nextInt();
withdraw(amount2);
System.out.println(“n”);
break;
case ‘4’:
System.out.println(“————————-“);
getPreviousTransaction();
System.out.println(“————————-“);
System.out.println(“n”);
break;
case ‘5’:
double initialInvestment = 0.0;
double interestRate = 0.0;
int numberOfYears = 0;
double total = 0.0;
Scanner input = new Scanner(System.in);
// Get the input from the user
initialInvestment = balance;
System.out.println(“Enter interest rate: “);
interestRate = input.nextDouble();
interestRate = interestRate * 0.01;
// System.out.println(interestRate);
System.out.println(“Enter number of years to complete: “);
numberOfYears = input.nextInt();
total = initialInvestment;
// Testing the input
// System.out.println(initialInvestment);
// System.out.println(interestRate);
// System.out.println(numberOfYears);
// Calculate the total
int counter = 1;
while (counter <= numberOfYears)
{
// code
// System.out.println(“Test loop”);
total += (total * interestRate);
counter++;
}
// Displaying the results
System.out.printf(“The initial investment is $%.2f and the total is$%.2fn”, balance, total);
System.out.println(“n”);
break;
case ‘6’:
System.out.println(“————————-“);
break;
default:
System.out.println(“Invalid option. Please enter again”);
break;
}
}while(option != ‘6’);
System.out.println(“Thank you”);
}
}
Expert Answer
Answer to JAVA coding HELP! I need to use case statements, but I’m not too sure If I did it for interest correctly. If someone cou… . . .
OR

