Kyron T.

asked • 04/26/22

JAVA CODE NEEDS MISSING CODE

This java code below done in java swing has missing code in the TODO sections down below within the code, I need help adding these missing lines please. I have bolded them in the code:


import java.awt.BorderLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import javax.swing.BorderFactory;

import javax.swing.ButtonGroup;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JRadioButton;


public class MovieStore2 {


private String[] Movie = {"The Tiki Temple", "Wrong Turn", "Revenge of the Nerds", "Sharly and Me"};

private final double[] MoviePrice = { 13.00, 12.75, 12.50, 12.55 };

private JRadioButton[] MovieButtons;


private String[] MovieSnacks ={"Popcorn", "Chocolate", "Sour Candies", "Pretzels"};

private final double[] SnacksPrice = { 7.50, 2.50 , 2.00, 6.00 };

private JRadioButton[] MovieSnacksButtons;


private String[] MovieDrinks ={"Juice", "Soda Pop", "Milkshake", "Water"};

private final double[] DrinksPrice = {2.25 , 2.50 , 4.50, 1.00};

private JRadioButton[] MovieDrinksButtons;




public MovieStore2()

{

JFrame frame = new JFrame();

frame.setTitle("MOVIE STORE");

frame.setSize(500, 200);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(getMoviePanel(), BorderLayout.WEST);

frame.add(getSnacksPanel(), BorderLayout.EAST);

frame.add(getDrinksPanel(), BorderLayout.CENTER);

frame.add(getTotalPanel(), BorderLayout.SOUTH);


frame.setVisible(true);


}



private JPanel getMoviePanel()

{

/** create the panel with a border and a 4x1 grid */

JPanel moviePanel = new JPanel();

moviePanel.setLayout(new GridLayout(4, 1));

/** add a border around the panel */

moviePanel.setBorder(BorderFactory.createTitledBorder("Movie"));

/** Create an array of radio buttons */

MovieButtons = new JRadioButton[Movie.length];

ButtonGroup group = new ButtonGroup();

/** initialize each radio button within the array */

for(int index = 0; index < MovieButtons.length; index++) {

MovieButtons[index] = new JRadioButton(Movie[index]);

/** group the radio buttons */

group.add(MovieButtons[index]);

/** add the radio buttons to the panel */

moviePanel.add(MovieButtons[index]);

}

return moviePanel;

}


private double getMovieCost() {

double MovieCost = 0.0;

for(int index = 0; index < MovieButtons.length; index++) {

if(MovieButtons[index].isSelected()) {

MovieCost = MoviePrice[index];

}

}

return MovieCost;

}

private JPanel getSnacksPanel()

{

/** create the panel with a border and a 4x1 grid */

JPanel snacksPanel = new JPanel();

snacksPanel.setLayout(new GridLayout(4, 1));

/** add a border around the panel */

snacksPanel.setBorder(BorderFactory.createTitledBorder("Snacks"));

/** Create an array of radio buttons */

MovieSnacksButtons = new JRadioButton[MovieSnacks.length];

ButtonGroup group = new ButtonGroup();

/** initialize each radio button within the array */

for(int index = 0; index < MovieSnacksButtons.length; index++) {

MovieSnacksButtons[index] = new JRadioButton(MovieSnacks[index]);

/** group the radio buttons */

group.add(MovieSnacksButtons[index]);

/** add the radio buttons to the panel */

snacksPanel.add(MovieSnacksButtons[index]);

}

return snacksPanel;

}


private double getSnacksCost() {

double MovieCost = 0.0;

for(int index = 0; index < MovieSnacksButtons.length; index++) {

if(MovieSnacksButtons[index].isSelected()) {

MovieCost = SnacksPrice[index];

}

}

return MovieCost;

}



private JPanel getDrinksPanel()

{

/** create the panel with a border and a 4x1 grid */

JPanel drinksPanel = new JPanel();

drinksPanel.setLayout(new GridLayout(4, 1));

/** add a border around the panel */

drinksPanel.setBorder(BorderFactory.createTitledBorder("Drinks"));

/** Create an array of radio buttons */

MovieDrinksButtons = new JRadioButton[MovieDrinks.length];

ButtonGroup group = new ButtonGroup();

/** initialize each radio button within the array */

for(int index = 0; index < MovieDrinksButtons.length; index++) {

MovieDrinksButtons[index] = new JRadioButton(MovieDrinks[index]);

/** group the radio buttons */

group.add(MovieDrinksButtons[index]);

/** add the radio buttons to the panel */

drinksPanel.add(MovieDrinksButtons[index]);

}

return drinksPanel;

}


private double getDrinksCost() {

double DrinksCost = 0.0;

for(int index = 0; index < MovieDrinksButtons.length; index++) {

if(MovieDrinksButtons[index].isSelected()) {

DrinksCost = DrinksPrice[index];

}

}

return DrinksCost;

}


/*********************************************************************

/** TODO Set up a GUI containing one button to calculate the total.

*********************************************************************/

/** TODO create getTotalPanel method */

/*********************************************************************/

public void getTotalCost(ActionEvent e) {

/** Sales tax rate */

final double TAX_RATE = 0.06;

double subtotal, tax, total;


subtotal = getMovieCost() +

getSnacksCost() +

getDrinksCost();


tax = getMovieCost() +

getSnacksCost() +

getDrinksCost();


total = getMovieCost() +

getSnacksCost() +

getDrinksCost();


/** TODO Display the charges using JOptionPane.showMessageDialog */

}

/*********************************************************************

* Launches the application.

*********************************************************************/

public static void main(String[] args)

{

new MovieStore2();

}

}

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.