Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//How can I get my Java code to run properly??? import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat; public class CarCare extends JFrame implements ActionListener{

//How can I get my Java code to run properly???

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat; public class CarCare extends JFrame implements ActionListener{ JMenuBar jmb = new JMenuBar(); JMenu oilMenu = new JMenu("Oil Change"); JMenu washMenu = new JMenu("Car Wash"); JMenu totalMenu = new JMenu("Total/Clear/Exit"); JMenuItem bronzeItem = new JMenuItem("Bronze"); JMenuItem silverItem = new JMenuItem("Silver"); JMenuItem goldItem = new JMenuItem("Gold"); JMenuItem basicItem = new JMenuItem("Basic"); JMenuItem betterItem = new JMenuItem("Better"); JMenuItem bestItem = new JMenuItem("Best"); JMenuItem totalItem = new JMenuItem("Total"); JMenuItem clearItem = new JMenuItem("Clear"); JMenuItem exitItem = new JMenuItem("Exit"); int cost = 0; String oil = ""; String wash = ""; public CarCare(){ this.setJMenuBar(jmb); jmb.add(oilMenu); jmb.add(washMenu); jmb.add(totalMenu); oilMenu.add(bronzeItem); oilMenu.add(silverItem); oilMenu.add(goldItem); JMenuItem totalItem = new JMenuItem("Total"); JMenuItem clearItem = new JMenuItem("Clear"); JMenuItem exitItem = new JMenuItem("Exit"); int cost = 0; String oil = ""; String wash = "";} public CarCare(){ this.setJMenuBar(jmb); jmb.add(oilMenu); jmb.add(washMenu); jmb.add(totalMenu); oilMenu.add(bronzeItem); oilMenu.add(silverItem); oilMenu.add(goldItem); washMenu.add(basicItem); washMenu.add(betterItem); washMenu.add(bestItem); totalMenu.add(totalItem); totalMenu.add(clearItem); totalMenu.add(exitItem); bronzeItem.addActionListener(this); silverItem.addActionListener(this); goldItem.addActionListener(this); basicItem.addActionListener(this); betterItem.addActionListener(this); bestItem.addActionListener(this); totalItem.addActionListener(this); clearItem.addActionListener(this); exitItem.addActionListener(this); } public void actionPerformed(ActionEvent e){ if (e.getSource() == bronzeItem) { cost += 20; oil = "Bronze"; } else if (e.getSource() == silverItem){ cost += 25; oil = "Silver"; } else if (e.getSource() == goldItem){ cost += 30; oil = "Gold"; } else if (e.getSource() == basicItem){ cost += 5; wash = "Basic"; } else if (e.getSource() == betterItem){ cost += 10; wash = "Better"; } else if (e.getSource() == bestItem){ cost += 15; wash = "Best"; } else if (e.getSource() == clearItem){ cost = 0; oil = ""; wash = ""; } else if (e.getSource() == totalItem){ DecimalFormat df = new DecimalFormat("$##.00"); JOptionPane.showMessageDialog(null, "Oil change: " + oil + " Car Wash: " + wash + " Total Cost: " + df.format(cost)); } else if (e.getSource() == exitItem){ System.exit(0); } else if (e.getSource() == goldItem){ cost += 30; oil = "Gold"; }else if (e.getSource() == basicItem){ cost += 5; wash = "Basic"; }else if (e.getSource() == betterItem){ cost += 10; wash = "Better"; }else if (e.getSource() == bestItem){ cost += 15; wash = "Best"; }else if (e.getSource() == clearItem){ cost = 0; oil = ""; wash = ""; }else if (e.getSource() == totalItem){ DecimalFormat df = new DecimalFormat("$##.00"); JOptionPane.showMessageDialog(null, "Oil change: " + oil + " Car Wash: " + wash + " Total Cost: " + df.format(cost)); }else if (e.getSource() == exitItem){ System.exit(0); } } public static void main(String[] args){ CarCare c = new CarCare(); c.setSize(675, 275); c.setVisible(true); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is human nature?

Answered: 1 week ago