Computer Science   Question , Create a GUI for the code below   import java.util.ArrayList; import java.util.List;   public class Budget { private String name; private double balance; private List expenses;   public Budget(String name, double balance) { this.name = name; this.balance = balance; this.expenses = new ArrayList<>(); }   public void addExpense(Expense expense) { if (expense.getAmount() <= this.balance) { this.expenses.add(expense); this.balance -= expense.getAmount(); } else { System.out.println("Error: not enough funds to add expense"); } }   public double getBalance() { return this.balance; }   public List getExpenses() { return this.expenses; } }     Step 2/2 Expense.java:     public class Expense { private String name; private double amount;   public Expense(String name, double amount) { this.name = name; this.amount = amount; }   public double getAmount() { return this.amount; }   public String toString() { return this.name + ": " + this.amount; } }     Here's an example usage of the Budget and Expense classes:   public class Main { public static void main(String[] args) { Budget budget = new Budget("Monthly Budget", 1000.0); Expense expense1 = new Expense("Rent", 800.0); Expense expense2 = new Expense("Groceries", 100.0); Expense expense3 = new Expense("Gas", 50.0);   budget.addExpense(expense1); budget.addExpense(expense2); budget.addExpense(expense3);   System.out.println("Expenses:"); for (Expense expense : budget.getExpenses()) { System.out.println(expense); }   System.out.println("Balance: " + budget.getBalance()); } }       Output:     Expenses: Rent: 800.0 Groceries: 100.0 Gas: 50.0 Balance: 50.0

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Computer Science

 

Question , Create a GUI for the code below

 

import java.util.ArrayList;

import java.util.List;

 

public class Budget {

private String name;

private double balance;

private List<Expense> expenses;

 

public Budget(String name, double balance) {

this.name = name;

this.balance = balance;

this.expenses = new ArrayList<>();

}

 

public void addExpense(Expense expense) {

if (expense.getAmount() <= this.balance) {

this.expenses.add(expense);

this.balance -= expense.getAmount();

} else {

System.out.println("Error: not enough funds to add expense");

}

}

 

public double getBalance() {

return this.balance;

}

 

public List<Expense> getExpenses() {

return this.expenses;

}

}

 

 

Step 2/2

Expense.java:

 

 

public class Expense {

private String name;

private double amount;

 

public Expense(String name, double amount) {

this.name = name;

this.amount = amount;

}

 

public double getAmount() {

return this.amount;

}

 

public String toString() {

return this.name + ": " + this.amount;

}

}

 

 

Here's an example usage of the Budget and Expense classes:

 

public class Main {

public static void main(String[] args) {

Budget budget = new Budget("Monthly Budget", 1000.0);

Expense expense1 = new Expense("Rent", 800.0);

Expense expense2 = new Expense("Groceries", 100.0);

Expense expense3 = new Expense("Gas", 50.0);

 

budget.addExpense(expense1);

budget.addExpense(expense2);

budget.addExpense(expense3);

 

System.out.println("Expenses:");

for (Expense expense : budget.getExpenses()) {

System.out.println(expense);

}

 

System.out.println("Balance: " + budget.getBalance());

}

}

 

 

 

Output:

 

 

Expenses:

Rent: 800.0

Groceries: 100.0

Gas: 50.0

Balance: 50.0

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education