QuestionQuestion

Transcribed TextTranscribed Text

Programming Project 4 The fourth programming project involves writing a program to manage a real estate database. This program should be comprised of an enumerated type, an interface and two classes. The enumerated type should be named Status and should contain three enumeration literals, FOR_SALE, UNDER_CONTRACT and SOLD. The interface should be a generic interface named StateChangeable and it should have a bounded generic type parameter whose type must be an enumerated type. It should contain one abstract method changeState that has a parameter whose type of the generic type parameter. The first of the two classes should be named Property. It should implement the StateChangeable interface. It should contain five instance variables, the property address stored as a string, the number of bedrooms, the square footage and the price, all stored as integers, and the status of the property whose type should be the enumerated type Status. In addition, it should have the following three methods: 1. A constructor that accepts four parameters for the purpose of initializing the characteristics of the property, the address, the number of bedrooms, the square footage and the price. The status of the property should be set to FOR_SALE. 2. A method named changeState that allows the status of the property to be changed. 3. An overridden toString method that returns a string containing the property address, the number of bedrooms, the square footage, the price and the current status, appropriately labeled. The second class named Project4 should contain the main method. In addition, it should contain an instance variable that defines the database of property records, which is implemented as a TreeMap, with the transaction number field as the key and a Property object as the value. It should generate the GUI shown below: Clicking the Process button should cause the selected choice of the three database actions in the combo box to its right to be executed. It should first check whether any non integer values have been entered in any of the fields that require integers. If so, an error message should be displayed in a JOptionPane window. The operation should be performed when the user clicks the Process button. If the user attempts to insert a key that is already in the database an error message should be displayed using a JOptionPane message dialog box. If the user attempts to delete or find a record that is not in the database, a message should also be displayed. After each successful operation is completed a JOptionPane window should be displayed confirming the success. In the case of a successful Find request, a window should pop up containing all the information in the associated Property object. . Clicking the Change Status button should cause status of the property association with the designated transaction number to be changed to status selected in the combo box to its right. Be sure to follow good programming style, which means making all instance variables private, naming all constants and avoiding the duplication of code. Furthermore you must select enough different kinds of transactions to completely test the program.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.TreeMap;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Project4 extends JFrame implements ActionListener {
    // defines the database of property records
    // with the transaction number field as the key and
    //a Property object as the value
    private TreeMap<Integer,Property> database ;
    private final String[] processItems = {"Insert","Delete","Find"}
                     , statusItems = {"FOR_SALE" ,
                         "UNDER_CONTRACT" , "SOLD"};
    private Color backGroundColor ;
    private Font font;
    private JPanel mainPane ;
    private JLabel transactionJLabel, addressJLabel, bedRoomsJLabel
            , squareFootageJLabel , priceJLabel;
    private JTextField transactionJTextField, addressJTextField,
            bedRoomsJTextField , squareFootageJTextField
            , priceJTextField;
    private JComboBox processJComboBox , statusJComboBox;
    private JButton processJButton , changeStatusJButton;
    //////////////////
    public Project4(){
       database = new TreeMap<Integer,Property>();
       database.clear();
       backGroundColor = new Color(240,240,240);
       font = new Font("Times New Roman", 0, 25);
       setWindowProperites();
    }
   
    /**
    * this function set Window Properites
    */
    private void setWindowProperites(){
       this.setFont(font);
       this.setTitle("Real Estate Database");
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       this.setBackground(backGroundColor);
       this.setSize(new Dimension(610, 450));
       this.setPreferredSize(new Dimension(610, 450));
       this.setResizable(false);
       this.setLocationRelativeTo(null);
       createMainPanel();
       this.setLayout(null);
       this.add(mainPane);
       this.setVisible(true);
      
    }
   
    /**
    * this function create Main Panel for JFrame (Window)
    */
    private void createMainPanel(){
       this.mainPane = new JPanel();
       this.mainPane.setSize(600,400);
       this.mainPane.setPreferredSize(new Dimension(600, 400));
       this.mainPane.setLocation(0,0);
       createJLabelComponents();
       createJComboBoxComponents();
       createJTextFieldComponents();
       createJButtonComponents();
       this.mainPane.setLayout(new GridLayout(0,2,30,30));
       this. mainPane.add(this.transactionJLabel);
       this.mainPane.add(this.transactionJTextField);
       this. mainPane.add(this.addressJLabel);
       this. mainPane.add(this.addressJTextField);
       this. mainPane.add(this.bedRoomsJLabel);
       this. mainPane.add(this.bedRoomsJTextField);
       this. mainPane.add(this.squareFootageJLabel);
       this. mainPane.add(this.squareFootageJTextField);
       this. mainPane.add(this.priceJLabel);
       this. mainPane.add(this.priceJTextField);
       this. mainPane.add(this.processJButton);
       this. mainPane.add(this.processJComboBox);
       this. mainPane.add(this.changeStatusJButton);
       this. mainPane.add(this.statusJComboBox);
    }
   
    /**
    * this function create JLabel Components
    */
    private void createJLabelComponents(){
       this.transactionJLabel = new JLabel();
       this.transactionJLabel.setFont(font);
       this.transactionJLabel.setText("Transaction No:");
       //////////////////////////
       this.addressJLabel = new JLabel();
       this.addressJLabel.setFont(font);
       this.addressJLabel.setText("Address:");
       //////////////////////////
       this.bedRoomsJLabel = new JLabel();
       this.bedRoomsJLabel.setFont(font);
       this.bedRoomsJLabel.setText("BedRooms:");
       //////////////////////////
       this.squareFootageJLabel = new JLabel();
       this.squareFootageJLabel.setFont(font);
       this.squareFootageJLabel.setText("Square Footage:");
       //////////////////////////
       this.priceJLabel = new JLabel();
       this.priceJLabel.setFont(font);
       this.priceJLabel.setText("Price:");
      
    }
   
    /**
    * this function create JComboBox Components
    */
    private void createJComboBoxComponents(){
       processJComboBox = new JComboBox<>(processItems);
       processJComboBox.setFont(font);
       processJComboBox.setSelectedIndex(0);
       processJComboBox.setActionCommand("process");
       processJComboBox.addActionListener(this);
       ///////////////////////////////////////////
       statusJComboBox = new JComboBox<>(statusItems);
       statusJComboBox.setFont(font);
       statusJComboBox.setSelectedIndex(0);
       statusJComboBox.setActionCommand("status");
       statusJComboBox.addActionListener(this);
      
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$50.00 $25.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats