Object-oriented classroom records

Source: Internet
Author: User
Tags quiesce

Package Com.hanqi;

public class Har {
Brand
Private String PINP;

Read
Public String Getpinp () {
return PINP;
}

Write properties
public void Setpinp (String pinp) {

System.out.println ("The car's brand is set to" + PINP);

THIS.PINP = PINP;
}

State
Private String Zhuangtai = "stationary";

Public String Getzhuangtai () {
return Zhuangtai;
}

Current Oil Quantity Properties

Private double Youliang = 0;

Public double Getyouliang () {
return Youliang;
}

Private double Youxiang;

public void Setyouxiang (double youxiang) {
This.youxiang = Youxiang;
}

Public double Getyouxiang () {
return Youxiang;
}

Overloading of a single fill method
public void Jiayou () {

System.out.println ("one refill");
Double yjyl = This.youxiang-this.youliang;

Jiayou (Yjyl);
}

Come on
public void Jiayou (double youliang) {
Mailbox capacity greater than 0
if (Youxiang <= 0) {
System.out.println ("Forgot to install the mailbox");
Return
}

Refueling capacity greater than 0
else if (Youliang < 0) {
System.out.println ("Don't Steal my Oil");
Return
} else if (!zhuangtai.equals ("Quiesce")) {
System.out.println ("The car stopped and refueling");
Return
}
Only when the static state can be added
Cannot exceed mailbox oil volume
else if (This.youliang + Youliang > This.youxiang) {
System.out.println ("The mailbox is full, do not add");
Double syyl = This.youliang;

This.youliang = This.youxiang;

System.out.println ("added this time" + (Youxiang-syyl) + "liter oil");

}

else {
This.youliang + = Youliang;
}

System.out.println ("added this time" + Youliang + "liter oil");
}

public void Fadong () {

if (This.youliang <= 0) {
System.out.println ("Kerosene, please refuel first");
}

else if (!this.getzhuangtai (). Equals ("Quiesce")) {
System.out.println ("The car has been launched");
} else {
This.zhuangtai = "Launch";

SYSTEM.OUT.PRINTLN ("car launched");

}
}

Private double Zongli;

Driving

Public double Getzongli () {
return Zongli;
}

public void Xingshi (double lic,double Youhao)
{//The state of the car is launched
if (!this.getzhuangtai (). Equals ("Start")) {

System.out.println ("Please start the car first");
}
else{
Double zyh = lic * YOUHAO/100;

Double LC = This.youliang *100/youhao;
if (LC < LIC) {
System.out.println ("Maximum travel" + lc+ "km");

This.zongli + = LC;
This.youliang = 0;

This.zhuangtai = "stationary";

}
else{
SYSTEM.OUT.PRINTLN ("Drive" + Lic + "km");
This.zongli + = lic;

This.zhuangtai = "Launch";
}
}
Calculate the total fuel consumption and determine if there is no oil.

}






/*
* Private String Zhuangtai () {//TODO auto-generated method stub return null;}
*/

Public Har ()//method name is consistent with class name; no return value is not void;
{

System.out.println ("Call a constructor method");
}

Overload
Public Har (String pinp) {

System.out.println ("The brand of the instanced car" + pinp);

THIS.PINP = PINP;

}

public static void Main (string[] args) {

Har har = new har ("BMW");//Default construction method


Har.fadong ();
Har.setyouxiang (40);

HAR.SETPINP ("BMW");

Har.jiayou (20);

SYSTEM.OUT.PRINTLN ("The amount of oil in the car is" + har.getyouliang () + "liter" + "+" car status is "+ Har.getzhuangtai ());

Har.fadong ();

Har.jiayou (10);

Har.xingshi (100, 10);

SYSTEM.OUT.PRINTLN ("The amount of oil in the car is" + har.getyouliang () + "liter" + "+" car status is "+ Har.getzhuangtai ());
Har.jiayou ();

SYSTEM.OUT.PRINTLN ("The amount of oil in the car is" + har.getyouliang () + "liter" + "+" car status is "+ Har.getzhuangtai ());

}

}

Object-oriented classroom records

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.