How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask ATLPROG Your Own Question

ATLPROG
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7677
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
44910485
Type Your Programming Question Here...
ATLPROG is online now
A new question is answered every 9 seconds

Having problems with Dorm and Meal Plan Calculator from

Customer Question

Customer: ***** *****. Having problems with Dorm and Meal Plan Calculator from Gaddis chapter 12 programming challenge 3. Instructor has a specific output that I haven't been able to achieve.
JA: Thanks. Can you give me any more details about your issue?
Customer: Java program. Here is the code that I have. package chapter12;/****** ***** Jo Leonard * Chapter 12 * Programming Challenge 3 * Dorm and Meal Plan Calculator */import java.awt.*; // Import common GUI elements.import java.awt.event.*; // Import common GUI event listeners.import javax.swing.*; // Import more common GUI elements. //DormAndMealPlanCalculator class. public class DormAndMealPlanCalc extends JFrame{ private static final long serialVersionUID = 1L; private JLabel label; // Display a message. private JPanel dormPanel; // To hold dorm panel components. private JPanel selectedDormPanel; // To hold selected dorm panel components. private JComboBox dormBox; // List of dorms. private JTextField selectedDorm; // Selected dorm. private JPanel mealPanel; // To hold meal panel components. private JPanel selectedMealPanel; // To hold selected meal panel components. private JComboBox mealBox; // List of meal plans. private JTextField selectedMeal; // Selected meal plan. private JButton calcButton; // To hold total panel component. private JTextField total; // Total plan. //Array to hold the values of the dormitory combo box. private String[] dorm = { "Allen Hall $" + 1500, "Pike Hall $" + 1600, "Farthing Hall $" + 1200, "University Suites $" + 1800 }; //Array to hold the dormitory rate. double[] dRate = {1500, 1600, 1200, 1800}; //Array to hold the values of the meal combo box. private String[] meal = { "7 Meals Per Week $" + 560, "14 Meals Per Week $" + 1095, "Unlimited Meals $" + 1500 }; //Array to hold the meal plan rate. double[] mRate = {560, 1095, 1500}; //Constructor. public DormAndMealPlanCalc() { setTitle("Dorm and Meal Plan Calculator."); // Set the title. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Specify action for close button. setLayout(new GridLayout(3,2)); // Create a border layout manager. // Build panels. buildDormPanel(); buildMealPanel(); buildTotalPanel(); // Add panels to content pane. add(dormPanel); add(mealPanel); add(calcButton); // Pack and display. pack(); setVisible(true); } //buildDormPanel function that adds a combo box with the dormitories to the panel. private void buildDormPanel() { dormPanel = new JPanel(); // Create panel to hold combo box. dormBox = new JComboBox(dorm); // Create the combo box. // Register an action listener. dormBox.addActionListener(new ComboBoxListener()); dormPanel.add(dormBox); } //buildMealPanel function that adds a combo box with the types of meals to the panel. private void buildMealPanel() { mealPanel = new JPanel(); // Create panel to hold combo box. mealBox = new JComboBox(meal); // Create the combo box. // Register an action listener. mealBox.addActionListener(new ComboBoxListener()); mealPanel.add(mealBox); } //buildSelectedDormPanel function adds a read-only text field to the panel. public void buildSelectedDormPanel() { selectedDormPanel = new JPanel(); // Create panel to hold components. label = new JLabel("Your Dormitory Is: "); // Create the label. // Create the uneditable text field. selectedDorm = new JTextField(20); selectedDorm.setEditable(false); // Add the label and text field to the panel. selectedDormPanel.add(label); selectedDormPanel.add(selectedDorm); } //buildSelectedMealPanel function adds a read-only text field to the panel. public void buildSelectedMealPanel() { selectedMealPanel = new JPanel(); // Create panel to hold components. label = new JLabel("Your Meal Plan Is: "); // Create the label. // Create the uneditable text field. selectedMeal = new JTextField(20); selectedMeal.setEditable(false); // Add the label and text field // to the panel. selectedMealPanel.add(label); selectedMealPanel.add(selectedMeal); } //buildTotalPanel function adds a read-only text field to the panel. private void buildTotalPanel() { calcButton = new JButton("Calculate"); // Create the uneditable text field. total = new JTextField(15); total.setEditable(false); } //Private inner class that handles the event when the //user selects an item from the combo box. private class ComboBoxListener implements ActionListener { public void actionPerformed(ActionEvent e) { // Declare variables. int dorm; int meal; double total1; // String total. // Get the selected dormitory. dormBox.getSelectedItem(); dorm = dormBox.getSelectedIndex(); // Get the selected meal plan. mealBox.getSelectedItem(); meal = mealBox.getSelectedIndex(); // Add the selections. total1 = dRate[dorm] + mRate[meal]; total.setText("$" + total1); JOptionPane.showMessageDialog(null, "Total Charges Per Semester: " + total1); } } //Main function. public static void main(String[] args) { new DormAndMealPlanCalc(); } } need to have an exit button and two decimals on the output. I can't seem to get this result.
JA: OK got it. Last thing — JustAnswer charges a fee (generally around $18) to post your type of question to Programming Experts (you only pay if satisfied). There are a couple customers ahead of you. Are you willing to wait a bit?
Customer: Yes. Thank you.
JA: OK. Now I'm going to take you to a page to place a secure deposit with JustAnswer. Don't worry, this chat is saved. After that, we will finish helping you.
Submitted: 11 months ago.
Category: Programming
Expert:  ATLPROG replied 11 months ago.

Hello do you still need help

Customer: replied 11 months ago.
No. Thank you. I got it.
Customer: replied 11 months ago.
Also I don't have a problem with the 5.00 deposit but I don't wish to pay the 46.00 as I never got a resolution from an expert.Thank you.
Expert:  ATLPROG replied 11 months ago.

Ok i will opt out for others

Customer: replied 11 months ago.
Thanks