<> Problem description :

<>     
   Define a car class , The class is required to contain at least 5 A private property ( Define the setting and getting methods for each property ), This class contains at least two construction methods ( A parameterless , One has a reference ), And include 5-6 There are two ways to describe the behavior of car objects ( One of the methods should be able to print out all the attribute values of the car object ).

<> Code display :
package experiment2; public class Bus { private String num;// license plate number private
String lineNum;// Line number private int maxCount;// Maximum capacity private String startTime;
// First departure time private String endTime;// Last bus time public String getNum() { return num; }
public void setNum(String num) { this.num = num; } public String getLineNum() {
return lineNum; } public void setLineNum(String lineNum) { this.lineNum =
lineNum; } public int getMaxCount() { return maxCount; } public void setMaxCount
(int maxCount) { this.maxCount = maxCount; } public String getStartTime() {
return startTime; } public void setStartTime(String startTime) { this.startTime
= startTime; } public String getEndTime() { return endTime; } public void
setEndTime(String endTime) { this.endTime = endTime; } public Bus(String num,
String lineNum,int maxCount,String startTime,String endTime) { this.setNum(num);
this.setLineNum(lineNum); this.setMaxCount(maxCount); this.setStartTime(
startTime); this.setEndTime(endTime); } public Bus() { //maxCount=60; this.
setNum(" Shaanxi AXXXXX"); this.setLineNum("170"); this.setMaxCount(100); this.
setStartTime("6:00"); this.setEndTime("21:00"); } public void drive() { System.
out.println(getLineNum()+" No.1 bus , Vehicle in motion , Please hold your seat ."); } public void debus() { System.
out.println(getLineNum()+" No.1 bus , Vehicle arrival , Please get off at the back door ."); } public void closed() {
System.out.println(getLineNum()+" No.1 bus , Off duty ."); } public void refuel() { System.
out.println(getLineNum()+" No.1 bus , It's refueling ."); } public void swipingCard() { System.
out.println(" drop ~~~"); } public void printBus() { System.out.println(" license plate number :"+getNum
()+" Line number :"+getLineNum()+" Maximum capacity :"+getMaxCount()+" First departure time :"+getStartTime()+"
Last bus time "+getEndTime()); } }
<> Define a test class for testing :
package experiment2; public class BusTest { public static void main(String[]
args) { // TODO Auto-generated method stub Bus bus1 = new Bus(); Bus bus2 = new
Bus(" Shaanxi AXXXXX","336",75,"6:00","0:00"); bus1.printBus(); bus2.printBus(); } }
Run it and see the output :

A simple bus class is written like this .

Technology
Daily Recommendation