Explore BrainMass

Programming: UML Diagrams

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Provide the UML would be for the the program below:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;

This program demonstrates a solution to the
Dorm and Meal Plan Calculator programming challenge.

public class DormAndMealPlanCalc extends JFrame
// Array with dorm names
private String[] dormNames = { "Allen Hall",
"Pike Hall",
"Farthing Hall",
"University Suites" };

// Array with meal plan descriptions
private String[] mealPlans = { "7 meals per week",
"14 meals per week",
"Unlimited meals per week" };

private JComboBox dormCombo; // Combo box to display dorms
private JComboBox mealCombo; // Combo box to display meal plans

private JButton calcButton; // To calculate prices
private JButton exitButton; // To exit the application

private JPanel dormPanel; // Panel for dorm combo box
private JPanel mealPanel; // Panel for meal combo box
private JPanel buttonPanel; // Panel for the buttons


public DormAndMealPlanCalc()
// Display a title.
setTitle("Dorm and Meal Plan Calculator");

// Specify what happens when the close button is clicked.

// Build the dorm panel.

// Build the meal plan panel.

// Build the button panel.

// Add the panels to the content pane.
add(dormPanel, BorderLayout.NORTH);
add(mealPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);

// Pack and display the window.

The buildDormPanel method builds a panel allowing the user
to select a dorm from a combo box.

private void buildDormPanel()
// Create a label prompting the user to select a dorm.
JLabel dormMsg = new JLabel("Select a Dorm.");

// Create the dorm combo box.
dormCombo = new JComboBox(dormNames);

// Put the components in a panel.
dormPanel = new JPanel();

The buildMealPanel method builds a panel allowing the user
to select a meal plan from a combo box.

private void buildMealPanel()
// Create a label prompting the user to select a meal plan.
JLabel mealMsg = new JLabel("Select a Meal Plan.");

// Create the meal plan combo box.
mealCombo = new JComboBox(mealPlans);

// Put the components in a panel.
mealPanel = new JPanel();

The buildButtonPanel method builds a panel with calculate
and exit buttons.

private void buildButtonPanel()
// Create a button to calculate the charges.
calcButton = new JButton("Calculate Charges");

// Add an action listener to the button.
calcButton.addActionListener(new CalcButtonListener());

// Create a button to exit the application.
exitButton = new JButton("Exit");

// Add an action listener to the button.
exitButton.addActionListener(new ExitButtonListener());

// Put the buttons in their own panel.
buttonPanel = new JPanel();

CalcButtonListener is an action listener class for the
calcbutton component.

private class CalcButtonListener implements ActionListener
actionPerformed method
@param e An ActionEvent object.

public void actionPerformed(ActionEvent e)
String selectedDorm; // To hold the selected dorm
String selectedMealPlan; // To hold the selected meal plan
double dormCharges; // Dorm charges
double mealCharges; // Meal plan charges
double totalCharges; // Total charges

// Create a DecimalFormat object to format output.
DecimalFormat dollar = new DecimalFormat("#,##0.00");

// Get the dorm charge.
selectedDorm = dormNames[dormCombo.getSelectedIndex()];
if (selectedDorm.equals("Allen Hall"))
dormCharges = 1500.0;
else if (selectedDorm.equals("Pike Hall"))
dormCharges = 1600.0;
else if (selectedDorm.equals("Farthing Hall"))
dormCharges = 1200.0;
else if (selectedDorm.equals("University Suites"))
dormCharges = 1800.0;
dormCharges = 0.0;

// Get the meal plan charge.
selectedMealPlan = mealPlans[mealCombo.getSelectedIndex()];
if (selectedMealPlan.equals("7 meals per week"))
mealCharges = 560.0;
else if (selectedMealPlan.equals("14 meals per week"))
mealCharges = 1095.0;
else if (selectedMealPlan.equals("Unlimited meals per week"))
mealCharges = 1500.0;
mealCharges = 0.0;

// Get the total charges
totalCharges = dormCharges + mealCharges;

// Display the message.
JOptionPane.showMessageDialog(null, "Total Charges per Semester: $" +
} // End of inner class

ExitButtonListener is an action listener class for the
exitButton component.

private class ExitButtonListener implements ActionListener
actionPerformed method
@param e An ActionEvent object.

public void actionPerformed(ActionEvent e)
} // End of inner class

The main method creates an instance of the DormAndMealPlanCalc
class, causing it to display its window.

public static void main(String[] args)
DormAndMealPlanCalc dmp = new DormAndMealPlanCalc();

© BrainMass Inc. brainmass.com October 25, 2018, 10:01 am ad1c9bdddf

Solution Preview

Please see the attached document for the UML diagram.

It is important to understand the reason for a UML diagram as it is an important part of programming so let's start with some basic information. When developing a small program, one may be able to start coding with little preparation. Often a program may need any number of classes and with large programs, it is important to resist coding until the program plan has been well thought out. This will allow the developer to create ...

Solution Summary

The following problem helps with programming and UML diagrams.

See Also This Related BrainMass Solution

UML Diagram and list of variables for programming group project

For many years, your Uncle Frank has been running a small landscaping business. Through these years, he acquired many steady clients and knew most of them on a first name basis. Once a month, after completing the work for that day, he would calculate (on the spot) how much the client owed for the month with services rendered each week; he would collect the payment and write a receipt.

His clients were charged various prices. Some clients were given a 10% discount because they were old friends. Some clients were given a $10.00 discount per lawn because of the amount of their business (5 lawns or more). New clients just paid the regular advertised price of $35.00 per lawn.

Recently, your uncle has hired some additional help because he has been getting older and can't do all the work like he used to. These employees are good and do a great job on landscaping, but for some reason, they have a hard time collecting payments. Either they forget to get a payment or they quote the wrong amount to the client. Your uncle knows he has to find a solution to this problem quickly; otherwise, he may go bankrupt.

At the next family gathering, your uncle asked you if you knew of any solutions for this problem. Since you are in college and taking a computer course, you know that this problem could easily be solved with the use of a computer.

After discussing this with your uncle, you agree to set up a computer and create a program that would keep track of his clients. It would calculate the bills and print invoices that would be mailed to the clients. It will also keep track of the client payments when they were received.

When the clients received their invoices, they would have 30 days to send in their payment. When the payment was received, the program would update the account to reflect this payment, but if no payment was received, then this month's bill would be added to next month's bill plus a 5% late charge.

Need to do the following:

1 - The Use Case Diagram

2 - A list of variables to be considered for the programming of the Uncle Frank project.

View Full Posting Details