Question: draw a uml diagram for the following code: / / - - - - - - - - - - - - - - -

draw a uml diagram for the following code:
//--------------------------------------------------------------------------------------------------------------
// Budget Tracker
// Program allows you to add and subtract expenses then check your total balance, keeping your budget organized
//--------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
// imports scanner
public class BudgetTracker {
private double balance;
public BudgetTracker(double initialBalance){
this.balance = initialBalance;
}
// establishes the balance as a double
public double getBalance(){
return balance;
}
// retrieves balance
public void addIncome(double amount){
balance += amount;
System.out.println("Income added: $"+ amount);
}
// adds income to balance
public void addExpense(double amount){
if (balance >= amount){
balance -= amount;
System.out.println("Expense added: $"+ amount);
} else {
System.out.println("Insufficient funds to add expense: $"+ amount);
// subtracts expense from balance if the balance will be greater than or equal to the expense
}
}
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter initial balance: ");
double initialBalance = scanner.nextDouble();
// stores initial value user inputs to add or subtract to in the future
BudgetTracker budgetTracker = new BudgetTracker(initialBalance);
boolean exit = false;
// if the user does not wish to exit the choices are brought back up
while (!exit){
System.out.println("
1. Add income");
System.out.println("2. Add expense amount");
System.out.println("3. Check balance");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice){
case 1:
System.out.print("Enter income amount: ");
double income = scanner.nextDouble();
budgetTracker.addIncome(income);
break;
// uses the addIncome to add amount entered to number stored
case 2:
System.out.print("Enter expense amount: ");
double expense = scanner.nextDouble();
budgetTracker.addExpense(expense);
break;
// uses the addExpense to add amount entered to number stored
case 3:
System.out.println("Current balance: $"+ budgetTracker.getBalance());
break;
// checks and prints current balance
case 4:
exit = true;
System.out.println("Exiting...");
break;
// exits the program
default:
System.out.println("Invalid choice. Please choose again.");
}
}
scanner.close();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!