Question

Can you please help me to run this Java program? I have no idea why it...

Can you please help me to run this Java program? I have no idea why it is not running.

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@SuppressWarnings({"unchecked", "rawtypes"})

public class SmartPhonePackages extends JFrame
{
private static final long serialVersionID= 6548829860028144965L;

private static final int windowWidth = 400;
private static final int windowHeight = 200;
private static final double SalesTax = 1.06;

private static JPanel panel;
private static JLabel lblPackages;
private static JLabel lblPhones;
private static JLabel lblOptions;
private static JLabel lblTotalls;
private static JLabel lblOutPutTotalls;
private static JComboBox cmbPackages;
private static JComboBox cmbCellPhones;
private static JList lstOptions;

private static String[] array = {
"8 gigabytes per month: 45.00 per"
+"month","16 gigabytes per month:65.00 per month"
+ "month", "20 gigabytes per"
+ "month: $99.00 per month"
};

private static String[] ArraySmartPhone =
{
"Model 100: $299.95",
"Model 110: $399.95",
"Model 200: $499.95"
};

private static String[] ArrayOptions =
{
"Phone Replacement Insurance: $5.00 per"
+ "month", "Wifi Hotspot Capability: $10.00 per month"
};

private DecimalFormat df = new DecimalFormat("#0.00");
private static double packageTotal;
private static double phoneTotal;
private static double optionTotal;

//Creating public constructor
public SmartPhonePackages()
{
//create a new window
JFrame window = new Jframe();

// Displaying the title
window.setTitle("Cell Phone Packages");

//Setting the size of the window
window.setTitle("Smart Phone Packages");

//Setting the size of the widnow
window.setSize(windowWidth, windowHeight);

//Close button
window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

//Building the panel and adding it to the frame
buildpanel();

//Adding the panel to the frame's content
window.add(panel);

//displaying window
windows.setVisible(true);
}

private void buildPanel()
{
lblPackages = new JLabel ("Select package:");
lblPhones = new JLabel ("Select cell phone:");
lblOptions = new JLabel ("select your options");
lblTotals = new Jlabel ("total:");
lblOutputTotal = new JLabel();

//Creating combo boxes
cmbPackages = new JComboBOX(array);
cmbCellPhones = new JComboBox(ArraySmartPhone);

lstOptions = new JList(ArrayOptions);
lstOptions.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

cmbPackages.AddActionListener (new packageListener());
cmbCellPhones.AddActionListener (new phoneListener());
lstOptions.AddListSelectionListener ( new optionsListerner());

panel = new Jpanel();

//Adding the components to the objects
panel.setLayout(new GridLayout(4.2));
panel.add(lblPakcages);
panel.add(cmbPackages);
panel.add(lblPhones);
panel.add(cmbCellPhones);
panel.add(lblOptions);
panel.add(lstOptions);
panel.add(lblTotalls);
panel.add(lblOutputTotal);
}

public class packageListener implements
ActionListener
{
@Override
public void ActionPerformed(ActionEvent e)
{
//collecting the data

int packageSelected = cmbPackages.getSelectedIndex();

if (packageSelected == 0)
{
packageTotal = 45;
}
else if (packageSelected ==1)
{
packageTotal = 65;
}
else if(packageSelected ==2 )
{
packageTotal = 99;
}

//Displaying total

lblOutputTotal.setText("$" + df.format(optionTotal + packageTotal + phoneTotal));
}
}

public class phoneListener implements
ActionListener
{
@override
public void actionPerformed(ActionEvent e)
{
int phoneSelected = cmbCellPhones.getSelectedIndex();

if (phoneSelected == 0)
{
phoneTotal = 299.95;
}
else if (phoneSelected == 1)
{
phoneTotal = 399.99;
}
else if (phoneSelected ==2)
{
phoneTotal = 499.95;
}

//calc sales tax

phoneTotal *= SalesTax;

//Displaying total
lblOutputTotal.setText("$" +df.format(optionTotal + packageTotal
+phoneTotal));
}
}

public class optionsListener implements
ListSelectionListener { public void valueChanged (ListSelectionEvent e)
{
double temp = 0;
int optionSelected[] = lstOpetions.getSelectedIndices();
for (int i = 0; i < optionSelected.length; i++)
{
if (optionSelected[i] == 0)
{
temp += 5;
}
if (optionSelected[i] == 1)
{
temp += 10;
}
}
optionTotal = temp;
lblOutputTotal.setText("$" + df.format(optionTotal + packageTotal + phoneTotal));
}
}
}

public static void main(String[] args) {
launch(args);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code after removing errors:

============================================================================================

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@SuppressWarnings({"unchecked", "rawtypes"})

public class SmartPhonePackages extends JFrame
{
private static final long serialVersionID= 6548829860028144965L;

private static final int windowWidth = 800;
private static final int windowHeight = 200;
private static final double SalesTax = 1.06;

private static JPanel panel;
private static JLabel lblPackages;
private static JLabel lblPhones;
private static JLabel lblOptions;
private static JLabel lblTotalls;
private static JLabel lblOutPutTotalls;
private static JComboBox cmbPackages;
private static JComboBox cmbCellPhones;
private static JList lstOptions;

private static String[] array = {
"8 gigabytes per month: 45.00 per"
+"month","16 gigabytes per month:65.00 per month"
+ "month", "20 gigabytes per"
+ "month: $99.00 per month"
};

private static String[] ArraySmartPhone =
{
"Model 100: $299.95",
"Model 110: $399.95",
"Model 200: $499.95"
};

private static String[] ArrayOptions =
{
"Phone Replacement Insurance: $5.00 per"
+ "month", "Wifi Hotspot Capability: $10.00 per month"
};

private DecimalFormat df = new DecimalFormat("#0.00");
private static double packageTotal;
private static double phoneTotal;
private static double optionTotal;

//Creating public constructor
public SmartPhonePackages()
{
//create a new window
JFrame window = new JFrame();

// Displaying the title
window.setTitle("Cell Phone Packages");

//Setting the size of the window
window.setTitle("Smart Phone Packages");

//Setting the size of the widnow
window.setSize(windowWidth, windowHeight);

//Close button
window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

//Building the panel and adding it to the frame
buildPanel();

//Adding the panel to the frame's content
window.add(panel);

//displaying window
window.setVisible(true);
}

private void buildPanel()
{
lblPackages = new JLabel ("Select package:");
lblPhones = new JLabel ("Select cell phone:");
lblOptions = new JLabel ("select your options");
lblTotalls = new JLabel ("total:");
lblOutPutTotalls = new JLabel();

//Creating combo boxes
cmbPackages = new JComboBox(array);
cmbCellPhones = new JComboBox(ArraySmartPhone);

lstOptions = new JList(ArrayOptions);
lstOptions.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

cmbPackages.addActionListener (new packageListener());
cmbCellPhones.addActionListener (new phoneListener());
lstOptions.addListSelectionListener ( new optionsListener());

panel = new JPanel();

//Adding the components to the objects
panel.setLayout(new GridLayout());
panel.add(lblPackages);
panel.add(cmbPackages);
panel.add(lblPhones);
panel.add(cmbCellPhones);
panel.add(lblOptions);
panel.add(lstOptions);
panel.add(lblTotalls);
panel.add(lblOutPutTotalls);
}

public class packageListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
//collecting the data

int packageSelected = cmbPackages.getSelectedIndex();

if (packageSelected == 0)
{
packageTotal = 45;
}
else if (packageSelected ==1)
{
packageTotal = 65;
}
else if(packageSelected ==2 )
{
packageTotal = 99;
}

//Displaying total

lblOutPutTotalls.setText("$" + df.format(optionTotal + packageTotal + phoneTotal));
}
}

public class phoneListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
int phoneSelected = cmbCellPhones.getSelectedIndex();

if (phoneSelected == 0)
{
phoneTotal = 299.95;
}
else if (phoneSelected == 1)
{
phoneTotal = 399.99;
}
else if (phoneSelected ==2)
{
phoneTotal = 499.95;
}

//calc sales tax

phoneTotal *= SalesTax;

//Displaying total
lblOutPutTotalls.setText("$" +df.format(optionTotal + packageTotal
+phoneTotal));
}
}

public class optionsListener implements ListSelectionListener
{
   public void valueChanged (ListSelectionEvent e)
{
double temp = 0;
int optionSelected[] = lstOptions.getSelectedIndices();
for (int i = 0; i < optionSelected.length; i++)
{
if (optionSelected[i] == 0)
{
temp += 5;
}
if (optionSelected[i] == 1)
{
temp += 10;
}
}
optionTotal = temp;
lblOutPutTotalls.setText("$" + df.format(optionTotal + packageTotal + phoneTotal));
}
}


public static void main(String[] args) {
new SmartPhonePackages();
}
}

============================================================================================

Output

Add a comment
Know the answer?
Add Answer to:
Can you please help me to run this Java program? I have no idea why it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have been messing around with java lately and I have made this calculator. Is there...

    I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show...

    In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show when my acceptbutton1 is pressed. One message is if the mouse HAS been dragged. One is if the mouse HAS NOT been dragged. /// I tried to make the Points class or the Mouse Dragged function return a boolean of true, so that I could construct an IF/THEN statement for the showDialog messages, but my boolean value was never accepted by ButtonHandler. *************************ButtonHandler class************************************...

  • Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10...

    Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10 seconds after the ON button is pushed and then goes off.   Put a new label on the lightbulb panel that counts the number of seconds the bulb is on and displays the number of seconds as it counts up from 0 to 10. THIS IS A JAVA PROGRAM. The image above is what it should look like. // Demonstrates mnemonics and tool tips. //********************************************************************...

  • 3.1 - In this exercise, you will see how to offer a user a selection among...

    3.1 - In this exercise, you will see how to offer a user a selection among multiple choices. You can place all choices into a combo box using the following code: /** File HelloViewer.java */ import javax.swing.JFrame; public class HelloViewer { public static void main(String[] args) { JFrame frame = new HelloFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("HelloViewer"); frame.setVisible(true); } } ---------------------------- /** File HelloFrame.java */ import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.BorderLayout; import java.awt.Font; public class HelloFrame extends JFrame { private String message; private...

  • Can someone modify my code so that I do not get this error: Exception in thread...

    Can someone modify my code so that I do not get this error: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1043) at java.awt.Container.add(Container.java:363) at RatePanel.<init>(RatePanel.java:64) at CurrencyConverter.main(CurrencyConverter.java:16) This code should get the amount of money in US dollars from user and then let them select which currency they are trying to convert to and then in the textfield print the amount //********************************************************************* //File name: RatePanel.java //Name: Brittany Hines //Purpose: Panel for a program that convers different currencyNamerencies to use dollars //*********************************************************************...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • Swing File Adder: Build a GUI that contains an input file, text box and Infile button....

    Swing File Adder: Build a GUI that contains an input file, text box and Infile button. It also must contain and output file, text box and Outfile button. Must also have a process button must read the infile and write to the outfile if not already written that is already selected and clear button. It must pull up a JFile chooser that allows us to brows to the file and places the full path name same with the output file.  Program...

  • JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but...

    JAVA JAR HELP...ASAP I have the code that i need for my game Connect 4, but i need to create a jar file . the instructions are below. It has to pass some parameters. I am really confused on doing so.l I dont know what to do next. Can someone help me and give detailed descritiopm opn how you ran the jar file in CMD import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Connect4 {               ...

  • Can you help me to link two frames in Java Swing and then if you click...

    Can you help me to link two frames in Java Swing and then if you click "Proceed button" it will link to the Second Frame...Thank you :) First frame code: //First import javax.swing.*; import java.awt.event.*; import java.io.*; public class Sample extends JFrame implements ActionListener { JMenuBar mb; JMenu file; JMenuItem open; JTextArea ta; JButton proceed= new JButton("Proceed"); Sample() { open = new JMenuItem("Open File"); open.addActionListener(this); file = new JMenu("File"); file.add(open); mb = new JMenuBar(); mb.setBounds(0, 0, 400, 20); mb.add(file); ta...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT