Guest User

Untitled

a guest
Jan 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1.  
  2. /**
  3. * Write a description of class Car here.
  4. *
  5. * @author (Kelsey Manoogian)
  6. * @version (Fall 2011)
  7. */
  8. public class Car
  9. {
  10.  
  11. private String makeModel;
  12. private int odometer;
  13. private int oilChangeMiles;
  14. private double gallonsInTank;
  15. private double mpg;
  16. private final double tank=12.5;
  17. private boolean engineOn;
  18. private boolean engineOff;
  19.  
  20. public Car()
  21. {
  22. mpg=22.7;
  23. makeModel="Generic Car";
  24. gallonsInTank=12.5;
  25. odometer=0;
  26. oilChangeMiles=5000;
  27. }
  28. public Car (String pMakeModel, double pMpg)
  29. {
  30. makeModel=pMakeModel;
  31. mpg=pMpg;
  32. }
  33. public int checkOdometer ( )
  34. {
  35. return odometer;
  36. }
  37. public double checkGallonsInTank ( )
  38. {
  39. return gallonsInTank;
  40. }
  41. public void honkHorn ( )
  42. {
  43. System.out.println("Toot! Toot! Toot!");
  44. }
  45. public void addGas (double g)
  46. {
  47. gallonsInTank=gallonsInTank+g;
  48. System.out.println("The " + makeModel+" has "+gallonsInTank+" gallons of gas.");
  49. if(gallonsInTank>12.5)
  50. System.out.println(makeModel+" is overflowing with gas.");
  51. if(g<=0)
  52. System.out.println(makeModel+ " can not take in negative gas amounts.");
  53. }
  54. public void drive (int miles)
  55. {
  56. if(miles>=0)
  57. odometer=odometer+miles;
  58. else
  59. odometer=odometer;
  60. if(miles>=0)
  61. gallonsInTank=gallonsInTank-(miles/mpg);
  62. else
  63. gallonsInTank=gallonsInTank;
  64. if(miles<=0)
  65. System.out.println("Invalid entry, "+makeModel+" cannot go negative speed.");
  66. if(gallonsInTank==0)
  67. System.out.println(makeModel+" has run out of gas after driving "+odometer+" miles.");
  68. }
  69. public void changeOil()
  70. {
  71. oilChangeMiles=odometer+5000;
  72. System.out.println("The "+makeModel+" got an oil change and needs another at "+oilChangeMiles+" miles.");
  73. }
  74. public void checkOil()
  75. {
  76. System.out.println("The "+makeModel+"'s oil is OK");
  77. }
  78. public void startEngine()
  79. {
  80. engineOn=true;
  81. if(engineOn)
  82. System.out.println("The "+makeModel+" engine started.");
  83. }
  84. public void stopEngine()
  85. {
  86. engineOff=false;
  87. if(engineOff)
  88. System.out.println("The "+makeModel+" engine is off.");
  89. }
  90. public static void main (String[]args)
  91. {
  92. Car car1=new Car();
  93. Car car2=new Car("Ford Mustang",25.5);
  94.  
  95. }
  96. }
Add Comment
Please, Sign In to add comment