JAVA help I am trying to create an application that allows t

JAVA help!

I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo boxes. The application should have a list component that allows the user to select multiple miscellaneous products. The application should display the subtotal, the amount of sales tax (at 6 percent), and the total of the order. Here\'s what it needs to have:

PROBLEM STATEMENT
Decks Truck Assemblies Wheels
The Master Thrasher $60 7.75 inch axle $35 51mm $20
The Dictator $45 8 inch axle $40 55mm $22
The Street King $50 8.5 inch axle $45 58mm $24
61mm $28
In addition, the Skate Shop sells the following miscellaneous products and services:
Grip tape: $10
Bearings: $30
Riser pads: $2
Nuts and bolts kit: $3

How come my program runs, and the values it puts out is 0.0 always?

WHEELSPANEL

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
@SuppressWarnings(\"unchecked\")

/**
   The WheelsPanel class allows the user to select different wheels.
*/

public class WheelsPanel extends JPanel implements ListSelectionListener
{

   private JPanel wheelsPanel;
   private JList wheelsList;
   public int selectedWheels;
String selection;

   private String[] wheels = {\"51mm\" , \"55mm\", \"58mm\", \"61mm\"};

   /**
       Constructor
   */

   public WheelsPanel()
   {
       // Create a GridLayout manager with
       // four rows and one column.
   setBorder(BorderFactory.createTitledBorder(\"Wheels\"));

wheelsList = new JList(wheels);
add(wheelsList);

wheelsList.setVisibleRowCount(2);
wheelsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
wheelsList.addListSelectionListener(this);
   // Create a GridLayout manager with

// Three rows and one column

setLayout(new GridLayout(2, 1));

}

public void valueChanged(ListSelectionEvent e)
{
if (!e.getValueIsAdjusting())
       {
selection = (String) wheelsList.getSelectedValue();
if (selection == \"51mm\")
               {
selectedWheels = 20;
}
if (selection == \"55mm\")
               {
selectedWheels = 22;
}
if (selection == \"58mm\")
               {
selectedWheels = 24;
}
               if (selection == \"61mm\")
               {
                   selectedWheels = 28;
               }
}
}
}

MISCELLANEOUS PANEL

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
@SuppressWarnings(\"unchecked\")

/**
   The MiscellaneousPanel class allows the user to select miscellaneous items.
*/

public class MiscellaneousPanel extends JPanel implements ListSelectionListener
{
   private JPanel miscellaneousPanel;
   private JList miscellaneousList;
   public int selectedMiscellaneous;
String selection;

   private String[] miscellaneous = {\"Grip Tape\" , \"Bearings\", \"Riser Pads\", \"Nuts & Bolts kit\"};

   /**
       Constructor
   */

   public MiscellaneousPanel()
   {
       setBorder(BorderFactory.createTitledBorder(\"Miscellaneous\"));

miscellaneousList = new JList(miscellaneous);
add(miscellaneousList);

miscellaneousList.setVisibleRowCount(2);
miscellaneousList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
miscellaneousList.addListSelectionListener(this);
   // Create a GridLayout manager with

// Three rows and one column

setLayout(new GridLayout(2, 1));

   }

public void valueChanged(ListSelectionEvent e)
{
if (!e.getValueIsAdjusting())
       {
selection = (String) miscellaneousList.getSelectedValue();
if (selection == \"Grip Tape\")
               {
selectedMiscellaneous = 10;
}
if (selection == \"Bearings\")
               {
selectedMiscellaneous = 30;
}
if (selection == \"Riser Pads\")
               {
selectedMiscellaneous = 2;
}
               if (selection == \"Nuts & Bolts kit\")
               {
                   selectedMiscellaneous = 3;
               }
}
}
}

DECK PANEL

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
@SuppressWarnings(\"unchecked\")

/**
The DeckPanel class allows the user to select either Master trasher, dictator, or street king.
*/

public class DeckPanel extends JPanel implements ListSelectionListener
{
// The following constants are used to indicate
// The different kind of decks

private JPanel deckPanel;
private JList deckList;
public int selectedDeck;
String selection;
String[] decks = {\"The Master Trasher\" , \"The Dictator\", \"The Street King\"};

/**
Constructor
*/

public DeckPanel()
{
// Add a border around the panel.
setBorder(BorderFactory.createTitledBorder(\"Decks\"));

deckList = new JList(decks);
add(deckList);
JScrollPane scrollbar = new JScrollPane(deckList);
scrollbar.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollbar.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(scrollbar);
deckList.setVisibleRowCount(2);
deckList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
deckList.addListSelectionListener(this);

// Create a GridLayout manager with
// Two rows and one column
setLayout(new GridLayout(3, 1));
}

public void valueChanged(ListSelectionEvent e)
{
if (!e.getValueIsAdjusting())
       {
selection = (String) deckList.getSelectedValue();
if (selection == \"The Master Trasher\")
               {
selectedDeck = 60;
}
if (selection == \"The Dictator\")
               {
selectedDeck = 45;
}
if (selection == \"The Street King\")
               {
selectedDeck = 50;
}
}
}
}

ASSEMBLIES PANEL

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
@SuppressWarnings(\"unchecked\")

/**
   The AssembliesPanel class allows the user to select
   the axles for the skateboard
*/

public class AssembliesPanel extends JPanel implements ListSelectionListener
{
   private JPanel assembliesPanel;
   private JList assembliesList;
   public int selectedAssemblies;
String selection;

   private String[] assemblies = {\"7.75 inch Axle\" , \"8 inch Axle\", \"8.5 inch Axle\"};

   /**
       Constructor
   */

   public AssembliesPanel()
   {
   // Add a border around the panel.
   setBorder(BorderFactory.createTitledBorder(\"Assemblies\"));

assembliesList = new JList(assemblies);
add(assembliesList);

assembliesList.setVisibleRowCount(3);
assembliesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
assembliesList.addListSelectionListener(this);

// Create a GridLayout manager with

// Three rows and one column

setLayout(new GridLayout(3, 1));


}

   public void valueChanged(ListSelectionEvent e)
{
if (!e.getValueIsAdjusting())
       {
selection = (String) assembliesList.getSelectedValue();
if (selection == \"7.75 inch Axle\")
               {
selectedAssemblies = 35;
}
if (selection == \"8 inch Axle\")
               {
selectedAssemblies = 40;
}
if (selection == \"8.5 inch Axle\")
               {
selectedAssemblies = 45;
}
}
}


}

ORDERCALUCULATORGUI

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

public class OrderCalculatorGUI extends JFrame
{
public double selectedWheels = 0.0;
public double selectedDeck = 0.0;
public double selectedAssemblies = 0.0;
public double selectedMiscellaneous = 0.0;
   private final int WINDOW_WIDTH = 400;               // window width
   private final int WINDOW_HEIGHT = 200;               // window height
   private DeckPanel decks;                               // Deck panel
   private AssembliesPanel assemblies;                   // Assemblies panel
   private WheelsPanel wheels;                           // Wheels panel
   private MiscellaneousPanel miscellaneous;           // To display a greeting
   private JPanel buttonPanel = new JPanel();       // To hold the buttons
   private JButton calcButton;                           // To calculate the cost
   private JButton exitButton;                           // To exit the application
   private final double TAX_RATE = 0.06;               // Sales tax rate

   public OrderCalculatorGUI()
   {
       // Display a title.
       setTitle(\"Skateboard Designer\");

       // Specify an action for the close button.
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       // set size of the window
       setSize(WINDOW_WIDTH, WINDOW_HEIGHT);

       // add gridlayout manager.
       setLayout(new GridLayout(3, 4));

       // Create the custom panels.
       miscellaneous = new MiscellaneousPanel();
       decks = new DeckPanel();
       assemblies = new AssembliesPanel();
       wheels = new WheelsPanel();

       // Create the button panel.
       /**
       buildDeckPanel();
       */
       buildButtonPanel();

       // Add the components to the content pane.
       add(decks);
       add(assemblies);
       add(wheels);
       add(miscellaneous);
       add(buttonPanel);

       // Pack the contents of the window and display it.
       pack();
       setVisible(true);
   }

/**
   The buildButtonPanel method builds the button panel.
*/

private void buildButtonPanel()
{
   // Create a panel for the buttons
   calcButton = new JButton(\"Calculate\");
   exitButton = new JButton(\"Exit\");

   // Register the action listeners.
   calcButton.addActionListener(new CalcButtonListener());
   exitButton.addActionListener(new ExitButtonListener());


   // Add the buttons to the button panel.
   buttonPanel.add(calcButton);
   buttonPanel.add(exitButton);
}

/**
   Private inner class that handles the event when
   the user clicks the Calculate button.
*/

private class CalcButtonListener implements ActionListener
{
   public void actionPerformed(ActionEvent e)
   {
       // Variables to hold the subtotal, tax, and total.
       double subtotal, tax, total;

       // Calculate the subtotal.
       subtotal = sum[selectedDeck + selectedAssemblies +selectedWheels + selectedMiscellaneous];

       // Calculate the sales tax.
       tax = subtotal * TAX_RATE;
       System.out.print(tax);
       // Calculate the total
       total = subtotal + tax;
       System.out.print(total);
       // Create a DecimalFormat object to format output.
       DecimalFormat dollar = new DecimalFormat(\"0.00\");

       // Display the charges.
       JOptionPane.showMessageDialog(null, \"Subtotal: $\" +
               dollar.format(subtotal) + \"\ \" +
               \"Tax: $\" + dollar.format(tax) + \"\ \" +
               \"Total: $\" + dollar.format(total));
               System.out.print(\"I am here\");
       }
   }

   /**
       Private inner class that handles the event when
       the user clicks the Exit button.
   */

   private class ExitButtonListener implements ActionListener
   {
       public void actionPerformed(ActionEvent e)
       {
           System.exit(0);
       }
   }
}

SKATEBOARD APP

/**
   This program creates an instance of the OrderCalculatorGUI class
   which displays the GUI for the Skateboard Designer application.
*/

public class SkateboardApp
{
   public static void main(String[] args)
   {
       new OrderCalculatorGUI();
   }
}

Solution

This is here where i think you have committed mistake and please do let me know if any errors occurs in the followeing

import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

The DeckPanel class allows the user to select either Master trasher, dictator, or street king.

public class DeckPanel extends JPanel implements ListSelectionListener

{

private JPanel deckPanel;

private JList deckList;

String[] decks = {\"The Master Trasher\" , \"The Dictator\", \"The Street King\"};

public DeckPanel()

{

setBorder(BorderFactory.createTitledBorder(\"Decks\"));

deckList = new JList(decks);

add(deckList);

JScrollPane scrollbar = new JScrollPane(deckList);

scrollbar.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

scrollbar.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

add(scrollbar);

deckList.setVisibleRowCount(2);

deckList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

deckList.addListSelectionListener(this);

setLayout(new GridLayout(3, 1));

}

public void valueChanged(ListSelectionEvent e)

    {

if (!e.getValueIsAdjusting())

{

String selection = (String) deckList.getSelectedValue();

System.out.println(selection);

}

}

}

JAVA help! I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo
JAVA help! I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo
JAVA help! I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo
JAVA help! I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo
JAVA help! I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo
JAVA help! I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo
JAVA help! I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo
JAVA help! I am trying to create an application that allows the user to select one deck, one truck assembly, and one wheel from either list components or combo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site