Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** An instantiable class which models a car in a rental company
- *@author Tommy O Shea*/
- public class Cars {
- private String carModel; //The Car Model
- private double carMilage; //The Cars Milage
- private String carReg; //The Cars Registration
- private String hireDate; //Date the car was hired
- /**accessor for the car model
- **@return the car model
- */
- public String getCarModel()
- { return carModel;}
- /**accessor for the cars milage
- **return the cars milage
- */
- public double getCarMilage()
- { return carMilage;}
- /**accessor for cars registration
- **return the cars registration
- */
- public String getCarReg()
- {return carReg;}
- /**accessor for date car was hired
- **return the cars hire date
- */
- public String getHireDate()
- {return hireDate;}
- /**mutator for car model
- **
- */
- public void setCarModel (String carModel) {
- this.carModel = carModel;
- }
- /**mutator for customers cars milage
- **
- */
- public void setCarMilage (double carMilage){
- this.carMilage = carMilage;
- }
- /**mutator for cars registration
- **
- */
- public void setCarReg (String carReg){
- this.carReg = carReg;
- }
- /**mutator for cars hire date
- **
- */
- public void setHireDate(String hireDate){
- this.hireDate = hireDate;
- }
- /**full args constructor
- *@param the cars milage
- *@param the cars model
- *@param the cars registration date
- *@param the cars hire date
- */
- public Cars (double carMilage,String carModel,String carReg,String hireDate) {
- setCarMilage(carMilage);
- setCarModel(carModel);
- setCarReg(carReg);
- setHireDate(hireDate);
- }
- /**
- *@return the name, phone number and address
- */
- public String toString() {
- return getCarMilage() + " " + getCarModel() + " " + getCarReg() + " " + getHireDate();
- }
- }
- /** An instantiable class which models a customer
- *@author Tommy O Shea*/
- public class Customers {
- private String name; //Customers Name
- private int phoneNumber; //Customers Phone Number
- private String address; //Customers Address
- /**accessor for customers name
- **@return the customers name
- */
- public String getName()
- { return name;}
- /**accessor for customers phone number
- **return the customers phone number
- */
- public int getPhoneNumber()
- { return phoneNumber;}
- /**accessor for customers address
- **return the customers address
- */
- public String getAddress()
- {return address;}
- /**mutator for customers name
- **
- */
- public void setName (String name) {
- this.name = name;
- }
- /**mutator for customers phone number
- **
- */
- public void setPhoneNumber (int phoneNumber){
- this.phoneNumber = phoneNumber;
- }
- /**mutator for customers address
- **
- */
- public void setAddress (String address){
- this.address = address;
- }
- /**full args constructor
- *@param the customers name
- *@param the customers phone number
- *@param the customers address
- */
- public Customers (String name,int phoneNumber,String address) {
- setName(name);
- setPhoneNumber(phoneNumber);
- setAddress(address);
- }
- /** no-args constructor, Customers c = new Customers()
- * to create a default Customer
- */
- public Customers() {
- this("Not Given",0,"Not Given");
- }
- /**
- *@return the name, phone number and address
- */
- public String toString() {
- return getName() + " " + getPhoneNumber() + " " + getAddress();
- }
- }
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class CarRentalCompany extends JFrame implements ActionListener {
- JMenu customerMenu,carMenu;
- JMenuItem quitItem;
- public void actionPerformed(ActionEvent e){
- String clicked = e.getActionCommand();
- if (clicked.equalsIgnoreCase("Add a customer"))
- name();
- else if (clicked.equalsIgnoreCase("Show customer phone number"))
- phoneNumber();
- else if (clicked.equalsIgnoreCase("Pay Up"))
- address();
- // treat quit option a little differently
- // since the quit item was declared up top and has its own name
- else if (e.getSource() == quitItem){
- JOptionPane.showMessageDialog(null, "Closing Down");
- System.exit(0);
- }
- else
- JOptionPane.showMessageDialog(null,"none of the above");
- }
- //Driver
- public static void main(String[] args) {
- CarRentalCompany frame = new CarRentalCompany();
- frame.setVisible(true);
- }
- public CarRentalCompany () {
- setTitle( "Car Rental Company" );
- setSize ( 400,200 );
- setLocation ( 100,100 );
- Container pane = getContentPane();
- // pane.setBackground(Color.WHITE);
- pane.setBackground(Color.WHITE);
- // create a menubar
- JMenuBar menuBar = new JMenuBar();
- setJMenuBar(menuBar);
- menuBar.setBackground(Color.ORANGE);
- //create a new Menu
- customerMenu = new JMenu("Customers");
- menuBar.add(customerMenu);
- carMenu = new JMenu("Cars");
- menuBar.add(carMenu);
- //terminates program
- setDefaultCloseOperation( EXIT_ON_CLOSE );
- }
- private void populateCustomerMenu(){
- JMenuItem item;
- item = new JMenuItem("Add a Customer");
- item.addActionListener(this);
- customerMenu.add(item);
- item = new JMenuItem("Show customer phone number");
- item.addActionListener(this);
- customerMenu.add(item);
- customerMenu.addSeparator();
- quitItem = new JMenuItem("Quit");
- quitItem.addActionListener(this);
- quitItem.setForeground(Color.red);
- customerMenu.add(quitItem);
- }
- public void addCustomers(){
- Customers customer1 = new Customers();
- customer1.setName(JOptionPane.showInputDialog("Enter the name of the customer"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement