Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Car {
- private int tank;
- private int speed;
- private Stereo stereo;
- public Car() {
- this.tank = 20;
- this.speed = 70;
- this.stereo = new Stereo();
- stereo.setVolume(100);
- stereo.setStation(50);
- }
- public Car(int tank, int speed, Stereo stereo) {
- this.tank = tank;
- this.speed = speed;
- this.stereo = new Stereo();
- }
- public int getTank() {
- return tank;
- }
- public int getSpeed() {
- return speed;
- }
- public int getStation() {
- return stereo.getStation();
- }
- public int getVolume() {
- return stereo.getVolume();
- }
- }
- public class Main {
- public static void main(String[] args) {
- Stereo stereo = new Stereo();
- Car car1 = new Car();
- Car car2 = new Car(30, 50, stereo);
- System.out.printf("Car 1 tank is: %d%n", car1.getTank());
- System.out.printf("Car 1 speed is: %d%n", car1.getSpeed());
- System.out.printf("Car 1 station is: %d%n", car1.getStation());
- System.out.printf("Car 1 volume is: %d%n%n", car1.getVolume());
- System.out.printf("Car 2 tank is: %d%n", car2.getTank());
- System.out.printf("Car 2 speed is: %d%n", car2.getSpeed());
- System.out.printf("Car 2 station is: %d%n", car2.getStation());
- System.out.printf("Car 2 volume is: %d%n", car2.getVolume());
- }
- }
- public class Stereo {
- private int station;
- private int volume;
- public void setStation(int station) {
- this.station = station;
- }
- public int getStation() {
- return station;
- }
- public void setVolume(int volume) {
- this.volume = volume;
- }
- public int getVolume() {
- return volume;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment