-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCarro.java
More file actions
executable file
·93 lines (75 loc) · 1.97 KB
/
Carro.java
File metadata and controls
executable file
·93 lines (75 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.util.Scanner;
public class Carro {
private String placa;
private double reserva, consumo, quantidade;
//private Scanner teclado = new Scanner(System.in);
public double getConsumo(){
return this.consumo;
}
public double getQuantidade(){
return this.quantidade;
}
public String getPlaca(){
return this.placa;
}
public void setConsumo(){
//System.out.println("Digite o consumo:");
//this.consumo = this.teclado.nextFloat();
this.consumo = Console.readDouble("Digite o consumo:");
}
public void setQuantidade(){
//System.out.println("Digite a quantidade:");
//this.quantidade = this.teclado.nextFloat();
this.quantidade = Console.readDouble("Digite a quantidade:");
}
public void setPlaca(){
//System.out.println("Digite a placa:");
//this.placa = this.teclado.next();
this.placa = Console.readString("Digite a placa:");
}
public double autonomiaKm(){
if (this.consumo > 0 && this.quantidade > 0){
return this.consumo * this.quantidade;
} else {
return 0;
}
}
public double kmParaReserva(){
if (this.consumo > 0 && this.quantidade > 0){
return (this.autonomiaKm() - (this.quantidade * this.reserva));
} else {
return 0;
}
}
public void mostraAutonomia(){
if (this.consumo > 0 && this.quantidade > 0){
System.out.println("Placa: "+this.placa);
System.out.println("Consumo: "+this.autonomiaKm()+"km");
System.out.println("Consumo até reserva: "+(this.autonomiaKm() - this.kmParaReserva())+"km");
} else {
System.out.println("Faltou definir os parametros");
}
}
public Carro(){
this.consumo = 0;
this.quantidade = 0;
this.placa = "";
this.reserva = 8;
}
public Carro(String p){
this();
this.placa = p;
}
public Carro(String p, float c, float q){
this(p);
this.consumo = c;
this.quantidade = q;
}
public static void main(String[] args) {
Carro carro1 = new Carro();
carro1.setPlaca();
carro1.setConsumo();
carro1.setQuantidade();
carro1.mostraAutonomia();
}
}