I need an answer to this question, it is easy but long. I hope
you can help me I will send you the code soon.
2.1 Considering the different levels of design. Design proper
software and submit a diagram corresponding to the different levels
of design.
3. Write down the source code for your system. Make sure to show at
least 1 example of the key OOP techniques:
• Encapsulation
• Inheritance
• Objects
• Classes Abstractions
• Polymorphism
• Inheritance
• Interfaces
Make sure to follow the design heuristics, so, you can have clean
and robust code.
4. Describe coupling and coherent in the lights of your code.
5. Have a clean code!
Discuss what does it mean to have a clean code with your group
mates and make sure to hand-in a clean code. Make sure that your
code is clean and that your code is of high quality: classes,
routines, variables, etc.
• Submit the source code + the related document on the course
submission page on Blackboard.
Milestone 3: Refactoring
1. You are required to use the techniques that have been covered in
the refactoring lectures to your code.
Remember that you do not have to change or alter the purpose of the
code.
2. You need to apply from the following techniques a minimum of
####:
• Composing Methods
✓ Extract Method
✓ Replace Temp with Query
✓ Explaining Variable
✓ Split Temporary Variable
✓ Remove Assignments to Parameters
• Simplifying Conditional Expressions
✓ Decompose Conditional
✓ Consolidate Conditional Expression
code 1
package p1;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class reserve extends JFrame implements ActionListener
{
JTextField fn = new JTextField();
JTextField ln = new JTextField();
JTextField ad = new JTextField();
JTextField phn = new JTextField();
JTextField em = new JTextField();
String[] day = new String[]{"1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23", "24", "24", "25", "26", "27", "28", "29",
"30", "31"};
JComboBox dayin;
String[] month;
JComboBox monthin;
String[] year;
JComboBox yearin;
JComboBox dayout;
JComboBox monthout;
JComboBox yearout;
JRadioButton k;
JRadioButton t;
JRadioButton j;
JRadioButton e;
JRadioButton r;
JTextField p;
JButton submit;
public reserve() {
this.dayin = new JComboBox(this.day);
this.month = new String[]{"1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12"};
this.monthin = new JComboBox(this.month);
this.year = new String[]{"2020", "2021", "2022"};
this.yearin = new JComboBox(this.year);
this.dayout = new JComboBox(this.day);
this.monthout = new JComboBox(this.month);
this.yearout = new JComboBox(this.year);
this.k = new JRadioButton("Superior King ");
this.t = new JRadioButton("Superior Twins ");
this.j = new JRadioButton("Junior Suite");
this.e = new JRadioButton("Executive Suite");
this.r = new JRadioButton("Royal Suite");
this.p = new JTextField();
this.submit = new JButton("Submit");
this.setDefaultCloseOperation(2);
this.setVisible(true);
this.setLayout((LayoutManager)null);
this.p.setEnabled(false);
JLabel guest = new JLabel(" Guest Information :");
guest.setFont(new Font("Courier", 1, 35));
this.add(guest);
guest.setBounds(20, 10, 500, 100);
JLabel fname = new JLabel("First Name :");
fname.setFont(new Font("Courier", 1, 25));
this.add(fname);
fname.setBounds(30, 90, 200, 100);
this.fn.setFont(new Font("Courier", 1, 20));
this.fn.setBounds(190, 123, 200, 45);
this.add(this.fn);
JLabel lname = new JLabel("Last Name :");
lname.setFont(new Font("Courier", 1, 25));
this.add(lname);
lname.setBounds(30, 200, 200, 100);
this.ln.setFont(new Font("Courier", 1, 20));
this.ln.setBounds(185, 233, 200, 45);
this.add(this.ln);
JRadioButton f = new JRadioButton("Female");
JRadioButton m = new JRadioButton("Male");
JLabel gender = new JLabel("Gender :");
gender.setFont(new Font("Courier", 1, 25));
this.add(gender);
gender.setBounds(30, 310, 200, 100);
f.setFont(new Font("Courier", 1, 20));
m.setFont(new Font("Courier", 1, 20));
f.setBounds(160, 315, 100, 100);
m.setBounds(160, 380, 100, 100);
ButtonGroup bg = new ButtonGroup();
bg.add(f);
bg.add(m);
this.add(f);
this.add(m);
JLabel address = new JLabel("Address :");
address.setFont(new Font("Courier", 1, 25));
this.add(address);
address.setBounds(30, 440, 300, 200);
this.ad.setFont(new Font("Courier", 1, 20));
this.ad.setBounds(160, 520, 260, 45);
this.add(this.ad);
JLabel phonenum = new JLabel("Phone Number :");
phonenum.setFont(new Font("Courier", 1, 25));
this.add(phonenum);
phonenum.setBounds(30, 560, 300, 200);
this.phn.setFont(new Font("Courier", 1, 18));
this.phn.setBounds(240, 640, 350, 45);
this.add(this.phn);
JLabel email = new JLabel("Email :");
email.setFont(new Font("Courier", 1, 25));
this.add(email);
email.setBounds(30, 680, 300, 200);
this.em.setFont(new Font("Courier", 1, 20));
this.em.setBounds(125, 760, 350, 45);
this.add(this.em);
JLabel datein = new JLabel("Check In Date :");
datein.setFont(new Font("Courier", 1, 25));
this.add(datein);
datein.setBounds(650, 40, 300, 200);
this.dayin.setFont(new Font("Courier", 1, 20));
this.dayin.setBounds(850, 123, 70, 40);
this.add(this.dayin);
this.monthin.setFont(new Font("Courier", 1, 20));
this.monthin.setBounds(955, 123, 130, 40);
this.add(this.monthin);
this.yearin.setFont(new Font("Courier", 1, 20));
this.yearin.setBounds(1120, 123, 70, 40);
this.add(this.yearin);
JLabel dateout = new JLabel("Check Out Date :");
dateout.setFont(new Font("Courier", 1, 25));
this.add(dateout);
dateout.setBounds(650, 150, 300, 200);
this.dayout.setFont(new Font("Courier", 1, 20));
this.dayout.setBounds(870, 233, 70, 40);
this.add(this.dayout);
this.monthout.setFont(new Font("Courier", 1, 20));
this.monthout.setBounds(975, 233, 130, 40);
this.add(this.monthout);
this.yearout.setFont(new Font("Courier", 1, 20));
this.yearout.setBounds(1140, 233, 70, 40);
this.add(this.yearout);
JLabel room = new JLabel("Room Type :");
room.setFont(new Font("Courier", 1, 25));
this.add(room);
room.setBounds(650, 300, 200, 100);
this.k.setFont(new Font("Courier", 1, 20));
this.k.setBounds(830, 305, 200, 100);
this.t.setFont(new Font("Courier", 1, 20));
this.t.setBounds(830, 380, 200, 100);
this.j.setFont(new Font("Courier", 1, 20));
this.j.setBounds(830, 455, 200, 100);
this.e.setFont(new Font("Courier", 1, 20));
this.e.setBounds(1050, 305, 200, 100);
this.r.setFont(new Font("Courier", 1, 20));
this.r.setBounds(1050, 370, 200, 100);
ButtonGroup bgr = new ButtonGroup();
bgr.add(this.k);
bgr.add(this.t);
bgr.add(this.j);
bgr.add(this.e);
bgr.add(this.r);
this.add(this.k);
this.add(this.t);
this.add(this.j);
this.add(this.e);
this.add(this.r);
JLabel nAdults = new JLabel("Number Of Adults :");
String[] num = new String[]{"1", "2", "3", "4"};
JComboBox adult = new JComboBox(num);
nAdults.setFont(new Font("Courier", 1, 25));
nAdults.setBounds(690, 570, 250, 40);
this.add(nAdults);
adult.setFont(new Font("Courier", 1, 20));
adult.setBounds(935, 570, 90, 40);
this.add(adult);
JLabel nChild = new JLabel("Number Of Children :");
String[] chinum = new String[]{"0", "1", "2", "3", "4"};
JComboBox child = new JComboBox(chinum);
nChild.setFont(new Font("Courier", 1, 25));
nChild.setBounds(690, 670, 250, 40);
this.add(nChild);
child.setFont(new Font("Courier", 1, 20));
child.setBounds(955, 670, 90, 40);
this.add(child);
JLabel price = new JLabel("Price:");
price.setFont(new Font("Courier", 1, 25));
this.add(price);
price.setBounds(690, 770, 100, 40);
this.p.setFont(new Font("Courier", 1, 18));
this.p.setBounds(770, 770, 200, 45);
this.add(this.p);
this.add(this.submit);
this.submit.setBackground(new Color(255, 255, 255));
this.submit.setFont(new Font("Courier", 1, 30));
this.submit.setBounds(520, 860, 170, 70);
this.submit.addActionListener(this);
this.k.addActionListener(this);
this.t.addActionListener(this);
this.j.addActionListener(this);
this.e.addActionListener(this);
this.r.addActionListener(this);
this.p.addActionListener(this);
this.setSize(1300, 1000);
this.setLocationRelativeTo((Component)null);
}
public void actionPerformed(ActionEvent ae)
{
if (this.k.isSelected()) {
this.p.setText("200$");
}
if (this.t.isSelected()) {
this.p.setText("250$");
}
if (this.j.isSelected()) {
this.p.setText("350$");
}
if (this.e.isSelected()) {
this.p.setText("800$");
}
if (this.r.isSelected()) {
this.p.setText("1000$");
}
if (ae.getSource() == this.submit)
{
if
(this.fn.getText().matches("[a-zA-Z]+") &
this.ln.getText().matches("[a-zA-Z]+") &
this.phn.getText().matches("[0][5][0-9]{8}") &
this.em.getText().matches("^[A-Za-z0-9_.]+@([a-zA-Z0-9]+[.]+[c][o][m])$"))
{
try {
FileWriter file = new FileWriter("hotel.txt", true);
BufferedWriter bufferedWriter = new
BufferedWriter(file);
bufferedWriter.write("Name :" + this.fn.getText() + " " +
this.ln.getText() + " phone number: " + this.phn.getText() +
" Price: " + this.p.getText() + " per day check in :" +
this.dayin.getSelectedItem() + "/" + this.monthin.getSelectedItem()
+ "/" + this.yearin.getSelectedItem() + " check out:" +
this.dayout.getSelectedItem() + "/" +
this.monthout.getSelectedItem() + "/" +
this.yearout.getSelectedItem() + "\n");
bufferedWriter.close();
} catch
(IOException var4) {
var4.printStackTrace();
}
new
read();
} else if
(!this.fn.getText().matches("[a-zA-Z]+")) {
JOptionPane.showMessageDialog((Component)null, "ERROR ! First Name
must contain only Letters ");
} else if
(!this.ln.getText().matches("[a-zA-Z]+")) {
JOptionPane.showMessageDialog((Component)null, "ERROR ! Last Name
must contain only Letters ");
} else if
(!this.phn.getText().matches("[0][5][0-9]{8}")) {
JOptionPane.showMessageDialog((Component)null, "ERROR ! Phone
Number must be in the form 05XXXXXXXX");
} else if
(!this.em.getText().matches("^[A-Za-z0-9_.]+@([a-zA-Z0-9]+[.]+[c][o][m])$"))
{
JOptionPane.showMessageDialog((Component)null, "ERROR ! Email must
contain @ and .com ");
}
}
}
}
********there is supplement to code but there is no
space*********
I need an answer to this question, it is easy but long. I hope you can help me I will send you the code soon. 2.1 Consid
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am