Advertisement
Guest User

Assignment 6

a guest
Apr 26th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. public class Car
  2. {
  3. private String make;
  4. private String model;
  5. private int year = 0;
  6. private int price = 0;
  7. private int totalPrice = 0;
  8.  
  9. public Car(String name)
  10. {
  11. this.make = make;
  12. this.model = model;
  13. year = 0;
  14. price = 0;
  15. totalPrice = 0;
  16. }
  17.  
  18. public void setMake (String mak)
  19. {
  20. make = mak;
  21. }
  22.  
  23. public void setModel (String mod)
  24. {
  25. model = mod;
  26. }
  27.  
  28. public void setYear (int yr)
  29. {
  30. year = yr;
  31. }
  32.  
  33. public void setPrice (int prc)
  34. {
  35. price = prc;
  36. }
  37.  
  38. public void settotalPrice (int tprc)
  39. {
  40. totalPrice = tprc;
  41. }
  42.  
  43. public String getMake()
  44. {
  45. return make;
  46. }
  47.  
  48. public String getModel()
  49. {
  50. return model;
  51. }
  52.  
  53. public int getYear()
  54. {
  55. return year;
  56. }
  57.  
  58. public int getPrice()
  59. {
  60. return price;
  61. }
  62.  
  63. public int gettotalPrice()
  64. {
  65. return totalPrice;
  66. }
  67.  
  68. public static void main(String[] args)
  69. {
  70. Car dodge = new Car("Dodge Dakota");
  71. dodge.setMake("Dodge");
  72. dodge.setModel("Dakota");
  73. dodge.setYear(2000);
  74. dodge.setPrice(15000);
  75. System.out.println("The car " + dodge.getMake() + " " + dodge.getModel() + " was made in the year " + dodge.getYear() + " for roughly " + dodge.getPrice() + " US dollars.");
  76.  
  77. Car honda = new Car("Honda CRV");
  78. honda.setMake("Honda");
  79. honda.setModel("CRV");
  80. honda.setYear(2009);
  81. honda.setPrice(20000);
  82. System.out.println("The car " + honda.getMake() + " " + honda.getModel() + " was made in the year " + honda.getYear() + " for roughly " + honda.getPrice() + " US dollars.");
  83.  
  84. Car pontiac = new Car("Pontiac LeMans");
  85. pontiac.setMake("Pontiac");
  86. pontiac.setModel("LeMans");
  87. pontiac.setYear(1970);
  88. pontiac.setPrice(3500);
  89. System.out.println("The car " + pontiac.getMake() + " " + pontiac.getModel() + " was made in the year " + pontiac.getYear() + " for roughly " + pontiac.getPrice() + " US dolalrs.");
  90.  
  91. Car totalPrice = new Car("Total Price");
  92. totalPrice.setPrice(dodge.getPrice() + honda.getPrice() + pontiac.getPrice());
  93. System.out.println("The total price of all three cars is " + totalPrice.gettotalPrice());
  94.  
  95. }
  96.  
  97.  
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement