Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application that will allow a new customer to order a house. You\'ll a

ID: 3584116 • Letter: C

Question

Create an application that will allow a new customer to order a house. You'll allow the customer to choose among four models (Aspen, Britattany, Colonial, and Dartmoor) by creating separate ButtonGroups. You'll also allow the to choose among four models (Aspen, Brittany, Colonial, and Dartmooor) by ceating separate ButtonGroups. You'll also allow the customer to choose a garage holding up to three cars. For each addition, include the following: + Aspen = $100,000 +Brittany=$120,000 +Colonial=$180,000 +Dartmoor=$250,000 +Each additional bedroom =$10,500 +Each car (0-3) = $7,775 Save the file as JMyNewHome.java. Your outcome should look similar to Figure. Aspen Brittany Colonial Dartmoor 2 bedrooms 3 bedrooms 4 bedrooms no garage 1 car 2 car 3 car

Explanation / Answer

// Jmynewhome.java import javax.swing.*; import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Jmynewhome extends JPanel implements ActionListener { JLabel priceLabel = new JLabel(); int housePrice = 0, bedroomPrice = 0, carPrice = 0; public void actionPerformed(ActionEvent e) { String action = e.getActionCommand(); if (action.contains("house")) { try { housePrice = Integer.parseInt(action.substring(6)); } catch (Exception ie) { ie.printStackTrace(); } } if (action.contains("bedroom")) { try { bedroomPrice = Integer.parseInt(action.substring(8)); } catch (Exception ie) { ie.printStackTrace(); } } if (action.contains("car")) { try { carPrice = Integer.parseInt(action.substring(4)); } catch (Exception ie) { ie.printStackTrace(); } } priceLabel.setText("This house will cost $"+(housePrice+bedroomPrice+carPrice)); } public Jmynewhome() { super(new BorderLayout()); if (!(this.getLayout() instanceof BorderLayout)) { this.add(new JLabel("Container doesn't use BorderLayout!")); return; } JLabel titleLabel = new JLabel("My new home builder"); this.add(titleLabel, BorderLayout.PAGE_START); //Create the radio buttons. // Aspen $100,000 Brittany $120,000 Colonial $180,000 Dartmoor $250,000 JRadioButton house1 = new JRadioButton("Aspen: $100,000"); house1.setActionCommand("house 100000"); JRadioButton house2 = new JRadioButton("Brittany: $120,000"); house2.setActionCommand("house 120000"); JRadioButton house3 = new JRadioButton("Colonial: $180,000"); house3.setActionCommand("house 180000"); JRadioButton house4 = new JRadioButton("Dartmoor: $250,000"); house4.setActionCommand("house 250000"); //Group the radio buttons. ButtonGroup group1 = new ButtonGroup(); group1.add(house1); group1.add(house2); group1.add(house3); group1.add(house4); //Register a listener for the radio buttons. house1.addActionListener(this); house2.addActionListener(this); house3.addActionListener(this); house4.addActionListener(this); //Put the radio buttons in a column in a panel. JPanel radioPanel1 = new JPanel(new GridLayout(0, 1)); radioPanel1.add(house1); radioPanel1.add(house2); radioPanel1.add(house3); radioPanel1.add(house4); this.add(radioPanel1, BorderLayout.LINE_START); //Create the radio buttons. JRadioButton bedroom2 = new JRadioButton("2 bedrooms"); bedroom2.setActionCommand("bedroom 0"); JRadioButton bedroom3 = new JRadioButton("3 bedrooms"); bedroom3.setActionCommand("bedroom 105000"); JRadioButton bedroom4 = new JRadioButton("4 bedrooms"); bedroom4.setActionCommand("bedroom 210000"); //Group the radio buttons. ButtonGroup group2 = new ButtonGroup(); group2.add(bedroom2); group2.add(bedroom3); group2.add(bedroom4); //Register a listener for the radio buttons. bedroom2.addActionListener(this); bedroom3.addActionListener(this); bedroom4.addActionListener(this); //Put the radio buttons in a column in a panel. JPanel radioPanel2 = new JPanel(new GridLayout(0, 1)); radioPanel2.add(bedroom2); radioPanel2.add(bedroom3); radioPanel2.add(bedroom4); this.add(radioPanel2, BorderLayout.CENTER); //Create the radio buttons. JRadioButton car0 = new JRadioButton("0 cars"); car0.setActionCommand("car 0"); JRadioButton car1 = new JRadioButton("1 car"); car1.setActionCommand("car 7775"); JRadioButton car2 = new JRadioButton("2 cars"); car2.setActionCommand("car 15500"); JRadioButton car3 = new JRadioButton("3 cars"); car3.setActionCommand("car 23325"); //Group the radio buttons. ButtonGroup group3 = new ButtonGroup(); group3.add(car0); group3.add(car1); group3.add(car2); group3.add(car3); //Register a listener for the radio buttons. car0.addActionListener(this); car1.addActionListener(this); car2.addActionListener(this); car3.addActionListener(this); //Put the radio buttons in a column in a panel. JPanel radioPanel3 = new JPanel(new GridLayout(0, 1)); radioPanel3.add(car0); radioPanel3.add(car1); radioPanel3.add(car2); radioPanel3.add(car3); this.add(radioPanel3, BorderLayout.LINE_END); priceLabel = new JLabel("Home price: "); this.add(priceLabel, BorderLayout.PAGE_END); } private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("Jmynewhome"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. JComponent newContentPane = new Jmynewhome(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { /* Use an appropriate Look and Feel */ try { //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } /* Turn off metal's use bold fonts */ UIManager.put("swing.boldMetal", Boolean.FALSE); //Schedule a job for the event dispatch thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote