Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error displaying value in the console.

$
0
0
I'm trying to display the Model number and Make of the car in the console. But, it seems I am getting the memory location of the variable?



public class Car {

	String carNumber;
	String carMake;

	public Car(String carNum, String carMake) {
		this.carNumber = carNum;
		this.carMake = carMake;
	}

	public static void main(String[] args) {

		Car c1 = new Car("Z100", "Nissan");
		Car c2 = new Car("G35", "Infinitti");
		Car c3 = new Car("M3", "BMW");
		
		CarWashOilChange cw1 = new CarWashOilChange(c1, true);
		cw1.clean();
		
		CarWashOilChange cw2 =  new CarWashOilChange(c2, true, true);
		cw2.clean();

		CarWashOilChange cw3 = new CarWashOilChange(c3, true, true, false);
		cw3.clean();
		
	}

}



package com.vulab.CarService;

public class CarWashOilChange {

	boolean interiorClean = false;
	boolean exteriorClean = false;
	boolean underBodyClean = false;
	boolean allClean = false;
	boolean oilChange = false;
	boolean wipersChange = false;
	Car car;

	public Car getCar() {
		return car;
	}


	public void setCar(Car car) {
		this.car = car;
	}


	public CarWashOilChange(Car c, boolean allClean) {
		this.car = c;
		this.allClean = allClean;
	}
	

	public CarWashOilChange(Car c, boolean IntClean, boolean ExtClean) {
		this.car = c;
		this.interiorClean = IntClean;
		this.exteriorClean = ExtClean;
	}

	public CarWashOilChange(Car c, boolean allClean, boolean oilChange,
			boolean wiperChange) {
		this.car = c;
		this.allClean = allClean;
		this.oilChange = oilChange;
		this.wipersChange = wiperChange;
	}

	public void clean() {
		if(this.interiorClean) {
			System.out.println("Interiors are getting cleaned on car " + this.car);
		}
		
		if(this.exteriorClean) {
			System.out.println("Exteriors are getting cleaned on car " + this.car);
		}
		
		if(this.underBodyClean) {
			System.out.println("Car UnderBody is getting services on car " + this.car);
		}
		
		if(this.allClean) {
			System.out.println("Your car is currently in a overall servicing stage on car " + this.car);
		}
		
		if(this.oilChange) {
			System.out.println("Car's oil is being changed and undergoing filter service on car " + this.car);
		}	
		
		if(this.wipersChange) {
			System.out.println("Wipers are being replaced on car " + this.car);
		}
	}


	@Override
	public String toString() {
		return "CarWashOilChange [car=" + car + "]";
	}
	
	
	
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>