Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. /** An instantiable class which models a car in a rental company
  2. *@author Tommy O Shea*/
  3.  
  4. public class Cars {
  5. private String carModel; //The Car Model
  6. private double carMilage; //The Cars Milage
  7. private String carReg; //The Cars Registration
  8. private String hireDate; //Date the car was hired
  9.  
  10. /**accessor for the car model
  11. **@return the car model
  12. */
  13. public String getCarModel()
  14. { return carModel;}
  15. /**accessor for the cars milage
  16. **return the cars milage
  17. */
  18. public double getCarMilage()
  19. { return carMilage;}
  20. /**accessor for cars registration
  21. **return the cars registration
  22. */
  23. public String getCarReg()
  24. {return carReg;}
  25. /**accessor for date car was hired
  26. **return the cars hire date
  27. */
  28. public String getHireDate()
  29. {return hireDate;}
  30.  
  31.  
  32. /**mutator for car model
  33. **
  34. */
  35. public void setCarModel (String carModel) {
  36. this.carModel = carModel;
  37. }
  38. /**mutator for customers cars milage
  39. **
  40. */
  41. public void setCarMilage (double carMilage){
  42. this.carMilage = carMilage;
  43. }
  44. /**mutator for cars registration
  45. **
  46. */
  47. public void setCarReg (String carReg){
  48. this.carReg = carReg;
  49. }
  50. /**mutator for cars hire date
  51. **
  52. */
  53. public void setHireDate(String hireDate){
  54. this.hireDate = hireDate;
  55. }
  56.  
  57. /**full args constructor
  58. *@param the cars milage
  59. *@param the cars model
  60. *@param the cars registration date
  61. *@param the cars hire date
  62. */
  63.  
  64. public Cars (double carMilage,String carModel,String carReg,String hireDate) {
  65. setCarMilage(carMilage);
  66. setCarModel(carModel);
  67. setCarReg(carReg);
  68. setHireDate(hireDate);
  69.  
  70.  
  71. }
  72. /**
  73. *@return the name, phone number and address
  74. */
  75.  
  76. public String toString() {
  77. return getCarMilage() + " " + getCarModel() + " " + getCarReg() + " " + getHireDate();
  78. }
  79.  
  80. }
  81.  
  82. /** An instantiable class which models a customer
  83. *@author Tommy O Shea*/
  84.  
  85. public class Customers {
  86. private String name; //Customers Name
  87. private int phoneNumber; //Customers Phone Number
  88. private String address; //Customers Address
  89.  
  90. /**accessor for customers name
  91. **@return the customers name
  92. */
  93. public String getName()
  94. { return name;}
  95. /**accessor for customers phone number
  96. **return the customers phone number
  97. */
  98. public int getPhoneNumber()
  99. { return phoneNumber;}
  100. /**accessor for customers address
  101. **return the customers address
  102. */
  103. public String getAddress()
  104. {return address;}
  105. /**mutator for customers name
  106. **
  107. */
  108. public void setName (String name) {
  109. this.name = name;
  110. }
  111. /**mutator for customers phone number
  112. **
  113. */
  114. public void setPhoneNumber (int phoneNumber){
  115. this.phoneNumber = phoneNumber;
  116. }
  117. /**mutator for customers address
  118. **
  119. */
  120. public void setAddress (String address){
  121. this.address = address;
  122. }
  123.  
  124. /**full args constructor
  125. *@param the customers name
  126. *@param the customers phone number
  127. *@param the customers address
  128. */
  129.  
  130. public Customers (String name,int phoneNumber,String address) {
  131. setName(name);
  132. setPhoneNumber(phoneNumber);
  133. setAddress(address);
  134. }
  135. /** no-args constructor, Customers c = new Customers()
  136. * to create a default Customer
  137. */
  138. public Customers() {
  139. this("Not Given",0,"Not Given");
  140.  
  141. }
  142.  
  143. /**
  144. *@return the name, phone number and address
  145. */
  146.  
  147. public String toString() {
  148. return getName() + " " + getPhoneNumber() + " " + getAddress();
  149. }
  150.  
  151. }
  152.  
  153.  
  154.  
  155. import javax.swing.*;
  156. import java.awt.*;
  157. import java.awt.event.*;
  158.  
  159.  
  160. public class CarRentalCompany extends JFrame implements ActionListener {
  161.  
  162. JMenu customerMenu,carMenu;
  163. JMenuItem quitItem;
  164.  
  165. public void actionPerformed(ActionEvent e){
  166. String clicked = e.getActionCommand();
  167.  
  168. if (clicked.equalsIgnoreCase("Add a customer"))
  169. name();
  170. else if (clicked.equalsIgnoreCase("Show customer phone number"))
  171. phoneNumber();
  172. else if (clicked.equalsIgnoreCase("Pay Up"))
  173. address();
  174.  
  175. // treat quit option a little differently
  176. // since the quit item was declared up top and has its own name
  177. else if (e.getSource() == quitItem){
  178. JOptionPane.showMessageDialog(null, "Closing Down");
  179. System.exit(0);
  180. }
  181.  
  182. else
  183. JOptionPane.showMessageDialog(null,"none of the above");
  184. }
  185.  
  186.  
  187.  
  188. //Driver
  189. public static void main(String[] args) {
  190. CarRentalCompany frame = new CarRentalCompany();
  191. frame.setVisible(true);
  192.  
  193. }
  194. public CarRentalCompany () {
  195.  
  196. setTitle( "Car Rental Company" );
  197. setSize ( 400,200 );
  198. setLocation ( 100,100 );
  199.  
  200. Container pane = getContentPane();
  201. // pane.setBackground(Color.WHITE);
  202. pane.setBackground(Color.WHITE);
  203. // create a menubar
  204. JMenuBar menuBar = new JMenuBar();
  205. setJMenuBar(menuBar);
  206. menuBar.setBackground(Color.ORANGE);
  207. //create a new Menu
  208. customerMenu = new JMenu("Customers");
  209. menuBar.add(customerMenu);
  210. carMenu = new JMenu("Cars");
  211. menuBar.add(carMenu);
  212.  
  213. //terminates program
  214. setDefaultCloseOperation( EXIT_ON_CLOSE );
  215.  
  216. }
  217. private void populateCustomerMenu(){
  218. JMenuItem item;
  219.  
  220. item = new JMenuItem("Add a Customer");
  221. item.addActionListener(this);
  222. customerMenu.add(item);
  223.  
  224. item = new JMenuItem("Show customer phone number");
  225. item.addActionListener(this);
  226. customerMenu.add(item);
  227.  
  228. customerMenu.addSeparator();
  229.  
  230. quitItem = new JMenuItem("Quit");
  231. quitItem.addActionListener(this);
  232. quitItem.setForeground(Color.red);
  233. customerMenu.add(quitItem);
  234. }
  235.  
  236. public void addCustomers(){
  237. Customers customer1 = new Customers();
  238. customer1.setName(JOptionPane.showInputDialog("Enter the name of the customer"));
  239.  
  240.  
  241. }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement