Charges for the semester. 4. Skateboard Designer The Skate Shop sells the skateb
ID: 3706817 • Letter: C
Question
Charges for the semester. 4. Skateboard Designer The Skate Shop sells the skateboard products listed in Table 13-2. Table 13-2 Skateboard products Decks The Master Thrasher $60 The Dictator $45 The Street King $50 Truck Assemblies 7.75 inch axle $35 8 inch axle $40 8.5 inch axle $45 Wheels 51 mm $20 55 mm $22 58 mm $24 61 mm $28 In addition, the Skate Shop sells the following miscellaneous products and services: Grip tape: $10 tas: 30 Bearings: $30 Riser pads: $2 Nuts & bolts kit: $3 Create an application that allows the user to select one deck, one wheel set from either list co list component that allows the user to select multiple mle applica should display the subtotal, the amount of sales tax (at 6 percent truck assembly, and one to select multiple miscellaneous products. The application 1 honning Cart SystemExplanation / Answer
Code
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
public class Skateboards extends JFrame implements ActionListener{
public JComboBox wheels;
public JComboBox trucks;
public JComboBox decks;
public JLabel deckLabel;
public JLabel truckLabel;
public JLabel wheelLabel;
public JLabel miscLabel;
public JLabel subLabel;
public JLabel subtotal;
public JLabel totalLabel;
public JLabel total;
public JLabel taxLabel;
public JLabel tax;
public JList misc;
public JButton calculate;
public String []deckString = {"Master Thrasher", "Dictator", "Street King"};
public String[] truckString = {"7.75 inch axle", "8 inch axle", "8.5 inch axle"};
public String[] wheelString = {"51 mm", "55 mm", "61 mm"};
public String[] miscString = {"Grip Tape", "Bearings","Riser Pads", "Nuts and Bolts Kit"};
public int[] deckPrices = {60, 45, 50};
public int[] truckPrices = {35, 40, 45};
public int[] wheelPrices = {20, 22, 28};
public int[] miscPrices = {10, 30, 2, 3};
public Skateboards(){
setSize(550,300);
setTitle("Skateboard Shop");
setLocation(150,150);
Container contentPane = getContentPane();
contentPane.setLayout(null);
contentPane.setBackground(Color.WHITE);
deckLabel = new JLabel("Decks:");
deckLabel.setBounds(57,17,80,25);
contentPane.add(deckLabel);
decks = new JComboBox(deckString);
decks.setBounds(5,40,150, 25);
contentPane.add(decks);
decks.setSelectedIndex(2);
truckLabel = new JLabel("Trucks:");
truckLabel.setBounds(240,17,80,25);
contentPane.add(truckLabel);
trucks = new JComboBox(truckString);
trucks.setBounds(190,40,150, 25);
contentPane.add(trucks);
trucks.setSelectedIndex(2);
wheelLabel = new JLabel("Wheels:");
wheelLabel.setBounds(430,17,80,25);
contentPane.add(wheelLabel);
wheels = new JComboBox(wheelString);
wheels.setBounds(375,40,150, 25);
contentPane.add(wheels);
wheels.setSelectedIndex(2);
misc = new JList(miscString); //data has type Object[]
misc.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
misc.setLayoutOrientation(JList.HORIZONTAL_WRAP);
misc.setVisibleRowCount(-1);
misc.setBounds(200, 100, 160, 80);
contentPane.add(misc);
miscLabel = new JLabel("Miscellaneous Services:");
miscLabel.setBounds(190,75, 150, 25);
contentPane.add(miscLabel);
subLabel = new JLabel("Subtotal: ");
subLabel.setBounds(150,210,120,25);
contentPane.add(subLabel);
totalLabel = new JLabel("Total: ");
totalLabel.setBounds(170, 250, 120, 25);
contentPane.add(totalLabel);
total = new JLabel();
total.setBounds(210, 250, 120, 25);
contentPane.add(total);
subtotal = new JLabel();
subtotal.setBounds(210, 210, 80, 25);
contentPane.add(subtotal);
taxLabel = new JLabel("Tax: ");
taxLabel.setBounds(175,230,80,25);
contentPane.add(taxLabel);
tax = new JLabel();
tax.setBounds(210, 230, 80, 25);
contentPane.add(tax);
calculate = new JButton("Calculate");
calculate.setBounds(200,180,120,25);
contentPane.add(calculate);
calculate.addActionListener(this);
}
public static void main(String[] args) {
Skateboards shop = new Skateboards();
shop.setVisible(true);
shop.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent arg0) {
calculateTotal();
}
public void calculateTotal(){
int wheelIndex = wheels.getSelectedIndex();
int deckIndex = decks.getSelectedIndex();
int truckIndex = trucks.getSelectedIndex();
int[] miscArray = misc.getSelectedIndices();
int miscTotal = 0;
for(int i =0; i<miscArray.length;i++){
miscTotal += miscPrices[miscArray[i]];
}
int subtotalPrice = wheelPrices[wheelIndex]+deckPrices[deckIndex]+truckPrices[truckIndex]+miscTotal;
Double taxPrice = (subtotalPrice*.06);
Double totalPrice = taxPrice+subtotalPrice;
subtotal.setText("$"+Integer.toString(subtotalPrice));
tax.setText("$" + Double.toString(taxPrice));
total.setText("$"+ Double.toString(totalPrice));
}
}