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 BudgetTrackerdouble initialBalance
this.balance initialBalance;
establishes the balance as a double
public double getBalance
return balance;
retrieves balance
public void addIncomedouble amount
balance amount;
System.out.printlnIncome added: $ amount;
adds income to balance
public void addExpensedouble amount
if balance amount
balance amount;
System.out.printlnExpense added: $ amount;
else
System.out.printlnInsufficient funds to add expense: $ amount;
subtracts expense from balance if the balance will be greater than or equal to the expense
public static void mainString args
Scanner scanner new ScannerSystemin;
System.out.printEnter initial balance: ;
double initialBalance scanner.nextDouble;
stores initial value user inputs to add or subtract to in the future
BudgetTracker budgetTracker new BudgetTrackerinitialBalance;
boolean exit false;
if the user does not wish to exit the choices are brought back up
while exit
System.out.println
Add income";
System.out.println Add expense amount";
System.out.println Check balance";
System.out.println Exit";
System.out.printEnter your choice: ;
int choice scanner.nextInt;
switch choice
case :
System.out.printEnter income amount: ;
double income scanner.nextDouble;
budgetTracker.addIncomeincome;
break;
uses the addIncome to add amount entered to number stored
case :
System.out.printEnter expense amount: ;
double expense scanner.nextDouble;
budgetTracker.addExpenseexpense;
break;
uses the addExpense to add amount entered to number stored
case :
System.out.printlnCurrent balance: $ budgetTracker.getBalance;
break;
checks and prints current balance
case :
exit true;
System.out.printlnExiting;
break;
exits the program
default:
System.out.printlnInvalid choice. Please choose again.";
scanner.close;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
