Question

Starting out with Java: From control structures through objects, 1e Complete the programming challenge Chapter 13...

Starting out with Java: From control structures through objects, 1e

Complete the programming challenge Chapter 13 #4 Make sure that you CREATE A MENU SYSTEM. The menu should have sub-menus for plans, phones, options, and a file menu that allows the user to exit the GUI. The total cost of the plan should be displayed and updated as the user makes menu choices.

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

package GUI;

import java.awt.event.*;

import javax.swing.*;

public class Menu extends JFrame implements ActionListener

{

JMenu plansM, phonesM, optionsM, fileM;

JMenuBar jmb;

JMenuItem exitMI, showPhoneMI, displayCostMI;

JCheckBoxMenuItem visitPuriCMI, visitKonarkCMI, visitParkCMI;

Menu()

{

jmb = new JMenuBar();

plansM = new JMenu("Plan");

phonesM = new JMenu("Phone");

optionsM = new JMenu("Options");

fileM = new JMenu("File");

exitMI = new JMenuItem("EXIT");

visitPuriCMI = new JCheckBoxMenuItem("Visit Puri");

visitKonarkCMI = new JCheckBoxMenuItem("Visit Konark");

visitParkCMI = new JCheckBoxMenuItem("Visit Park");

showPhoneMI = new JMenuItem("Visit Contact");

displayCostMI = new JMenuItem("Total Cost");

setJMenuBar(jmb);

jmb.add(fileM);

jmb.add(plansM);

jmb.add(phonesM);

jmb.add(optionsM);

fileM.add(exitMI);

plansM.add(visitPuriCMI);

plansM.add(visitKonarkCMI);

plansM.add(visitParkCMI);

phonesM.add(showPhoneMI);

optionsM.add(displayCostMI);

exitMI.addActionListener(this);

visitPuriCMI.addActionListener(this);

visitKonarkCMI.addActionListener(this);

visitParkCMI.addActionListener(this);

showPhoneMI.addActionListener(this);

displayCostMI.addActionListener(this);

// Sets the size of the frame

setSize(300, 300);

// Sets the location to center of the window

setLocationRelativeTo(null);

// Sets the visible to true

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e)

{

double amount = 0.0;

int flag = 0;

if(exitMI.isSelected())

System.exit(0);

if(visitPuriCMI.isSelected() && visitKonarkCMI.isSelected() &&

visitParkCMI.isSelected())

{

JOptionPane.showMessageDialog(null, "Visit Puri Cost $ " + 500 +

"\n Visit Konark Cost $ " + 1000 + "Visit Park Cost $ " + 200);

amount += 1700;

}

else if(visitPuriCMI.isSelected() && visitKonarkCMI.isSelected())

{

JOptionPane.showMessageDialog(null, "Visit Puri Cost $ " + 500 +

"\n Visit Konark Cost $ " + 1000);

amount += 1500;

}

else if(visitPuriCMI.isSelected() && visitParkCMI.isSelected())

{

JOptionPane.showMessageDialog(null, "Visit Puri Cost $ " + 500 +

"\n Visit Park Cost $ " + 200);

amount += 700;

}

else if(visitKonarkCMI.isSelected() && visitParkCMI.isSelected())

{

JOptionPane.showMessageDialog(null, "Visit Konark Cost $ " + 1000 +

"\n Visit Park Cost $ " + 200);

amount += 1200;

}

else if(visitPuriCMI.isSelected())

{

JOptionPane.showMessageDialog(null, "Visit Puri Cost $ " + 500);

amount += 500;

}

else if(visitKonarkCMI.isSelected())

{

JOptionPane.showMessageDialog(null, "Visit Konark Cost $ " + 1000);

amount += 1000;

}

else if(visitParkCMI.isSelected())

{

JOptionPane.showMessageDialog(null, "Visit Park Cost $ " + 200);

amount += 200;

}

if(displayCostMI.isSelected())

JOptionPane.showMessageDialog(null, "Your Traveling Cost $" + amount);

if(showPhoneMI.isSelected())

{

JOptionPane.showMessageDialog(null, "In Contact");

if(visitPuriCMI.isSelected() && visitKonarkCMI.isSelected() &&

visitParkCMI.isSelected())

JOptionPane.showMessageDialog(null, "Visit Puri Mobile: 9440999477" +

"\n Visit Konark Mobile: 9880911175" +

"\n Visit Park Mobile: 9666111444");

else if(visitPuriCMI.isSelected() && visitKonarkCMI.isSelected())

JOptionPane.showMessageDialog(null, "Visit Puri Mobile: 9440999477" +

"\n Visit Konark Mobile: 9880911175");

else if(visitPuriCMI.isSelected() && visitParkCMI.isSelected())

JOptionPane.showMessageDialog(null, "Visit Puri Mobile: 9440999477" +

"\n Visit Park Mobile: 9666111444");

else if(visitKonarkCMI.isSelected() && visitParkCMI.isSelected())

JOptionPane.showMessageDialog(null, "Visit Konark Mobile: 9880911175" +

"\n Visit Park Mobile: 9666111444");

else if(visitPuriCMI.isSelected())

JOptionPane.showMessageDialog(null, "Visit Puri Mobile: 9440999477");

else if(visitKonarkCMI.isSelected())

JOptionPane.showMessageDialog(null, "Visit Konark Mobile: 9880911175");

else if(visitParkCMI.isSelected())

JOptionPane.showMessageDialog(null, "Visit Park Mobile: 9666111444");

}

}

// main method definition

public static void main(String[] pyari)

{

// Calls the constructor using anonymous object

new Menu();

}// End of main method

}// End of driver class

Add a comment
Know the answer?
Add Answer to:
Starting out with Java: From control structures through objects, 1e Complete the programming challenge Chapter 13...
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
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