banaandrew

Car Problem

Jul 24th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1.  
  2. public class Car {
  3.  
  4. private int tank;
  5. private int speed;
  6. private Stereo stereo;
  7.  
  8. public Car() {
  9. this.tank = 20;
  10. this.speed = 70;
  11. this.stereo = new Stereo();
  12. stereo.setVolume(100);
  13. stereo.setStation(50);
  14. }
  15.  
  16. public Car(int tank, int speed, Stereo stereo) {
  17. this.tank = tank;
  18. this.speed = speed;
  19. this.stereo = new Stereo();
  20. }
  21.  
  22. public int getTank() {
  23. return tank;
  24. }
  25. public int getSpeed() {
  26. return speed;
  27. }
  28. public int getStation() {
  29. return stereo.getStation();
  30. }
  31. public int getVolume() {
  32. return stereo.getVolume();
  33. }
  34.  
  35. }
  36.  
  37.  
  38. public class Main {
  39.  
  40. public static void main(String[] args) {
  41.  
  42. Stereo stereo = new Stereo();
  43.  
  44. Car car1 = new Car();
  45. Car car2 = new Car(30, 50, stereo);
  46.  
  47. System.out.printf("Car 1 tank is: %d%n", car1.getTank());
  48. System.out.printf("Car 1 speed is: %d%n", car1.getSpeed());
  49. System.out.printf("Car 1 station is: %d%n", car1.getStation());
  50. System.out.printf("Car 1 volume is: %d%n%n", car1.getVolume());
  51.  
  52. System.out.printf("Car 2 tank is: %d%n", car2.getTank());
  53. System.out.printf("Car 2 speed is: %d%n", car2.getSpeed());
  54. System.out.printf("Car 2 station is: %d%n", car2.getStation());
  55. System.out.printf("Car 2 volume is: %d%n", car2.getVolume());
  56.  
  57. }
  58. }
  59.  
  60.  
  61. public class Stereo {
  62.  
  63. private int station;
  64. private int volume;
  65.  
  66. public void setStation(int station) {
  67. this.station = station;
  68. }
  69. public int getStation() {
  70. return station;
  71. }
  72.  
  73. public void setVolume(int volume) {
  74. this.volume = volume;
  75. }
  76. public int getVolume() {
  77. return volume;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment