1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Car.java

Posted at

class Car{
private String name;
private String color;
private int distance = 0;
private int fuel = 100;
Car(String name,String color){
this.name = name;
this.color = color;
}

public void printData(){
System.out.println("名前:"+this.name);
System.out.println("色:"+ this.color);
System.out.println("走行距離:"+this.distance+"km");
System.out.println("ガソリン量:"+this.fuel+"L");
}
public void run(int distance){
System.out.println(distance+"km走ります");
if(distance <= this.fuel){
this.distance += distance;
this.fuel -= distance;
}else{
System.out.println("ガソリンが足りません");
}

System.out.println("走行距離:"+this.distance+"km");
System.out.println("ガソリン量:"+this.fuel+"L");

}
public void charge(int litre){
System.out.println(litre+"L給油します");
if(litre <=0){
System.out.println("給油できません");
}else if(litre >=100){
System.out.println("満タンまで給油します");
this.fuel = 100;
}else{
this.fuel += litre;
}
System.out.println("ガソリン量:"+this.fuel+"L");
}
}

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?