Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TEACHING-MATERIALS/Week_02_The_Java_language/MyVehicle/app/src/main/java/com/example/jianhuayang/myvehicle/Vehicle.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
58 lines (44 sloc)
1.04 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.jianhuayang.myvehicle; | |
/** | |
* Created by jianhuayang on 09/10/2017. | |
*/ | |
public class Vehicle { | |
public static int counter = 0; | |
private String make; | |
private int year; | |
private String message; | |
// the default constructor | |
public Vehicle() { | |
this.make = "Volvo"; | |
this.year = 2012; | |
this.message = "This is the default message."; | |
} | |
/* | |
* This constructor takes two parameters. | |
*/ | |
public Vehicle(String make, int year) { | |
this.make = make; | |
this.year = year; | |
this.message = "Your car is a " + make + " built in " + year + "."; | |
count(); | |
} | |
/** | |
* @param make the make of your car | |
*/ | |
public Vehicle(String make) { | |
this(); | |
this.make = make; | |
message = "You didn't type in year value."; | |
count(); | |
} | |
public String getMessage() { | |
return message; | |
} | |
@Override | |
public String toString() { | |
return message; | |
} | |
private void count() { | |
this.counter++; | |
} | |
} | |