Meu código: Class Car
import java.util.Scanner;
public class Car {
public String Model;
private String mark;
private double valueYear1;
private double valueYear2;
private double valueYear3;
private int years;
Scanner scanner = new Scanner(System.in);
public String getModel() {
return Model;
}
public void setCarModel(String carModel) {
this.Model = carModel;
}
public String getMark() {
return mark;
}
public void setMark(String mark) {
this.mark = mark;
}
public double getValueYear1() {
return valueYear1;
}
public void setValueYears(double valueYears) {
this.valueYear1 = valueYears;
}
public double getValueYear2() {
return valueYear2;
}
public void setValueYear2(double valueYear2) {
this.valueYear2 = valueYear2;
}
public double getValueYear3() {
return valueYear3;
}
public void setValueYear3(double valueYear3) {
this.valueYear3 = valueYear3;
}
public int getYears() {
return years;
}
public void setYears(int years) {
this.years = years;
}
public void printCar() {
System.out.println("Qual o modelo do veículo?");
setCarModel(this.Model = scanner.nextLine());
System.out.println("Qual a marca?");
setMark(this.mark = scanner.nextLine());
}
public void printValue() {
System.out.println("Insira os 3 primeiros anos do veículo: ");
setYears(this.years = scanner.nextInt());
setYears(this.years = scanner.nextInt());
setYears(this.years = scanner.nextInt());
System.out.println("Insira o valor do veículo no primeiro ano: ");
setValueYears(this.valueYear1 = scanner.nextDouble());
System.out.println("Insira o valor do veículo no segundo ano: ");
setValueYears(this.valueYear2 = scanner.nextDouble());
System.out.println("Insira o valor do veículo no terceiro ano: ");
setValueYears(this.valueYear3 = scanner.nextDouble());
}
public void printall() {
System.out.println("========== SEUS DADOS ==========");
System.out.println("Marca do veículo: " + getMark());
System.out.println("Modelo do veículo: " + getModel());
System.out.println("Valor do veículo no primeiro ano " + getValueYear1());
System.out.println("Valor do veículo no segundo ano " + getValueYear2());
System.out.println("Valor do veículo no terceiro ano " + getValueYear3());
System.out.println("O maior valor é: " + valueGreater());
System.out.println("O menor valor é: " + valueLowest());
}
private double valueLowest() {
if (getValueYear1() < getValueYear2()) {
if (getValueYear1() < getValueYear3()) {
return getValueYear1();
} else {
return getValueYear3();
}
} else {
if (getValueYear2() < getValueYear3()) {
return getValueYear2();
} else {
return getValueYear3();
}
}
}
private double valueGreater() {
if (getValueYear1() > getValueYear2()) {
if (getValueYear1() > getValueYear3()) {
return getValueYear1();
} else {
return getValueYear3();
}
} else {
if (getValueYear2() > getValueYear3()) {
return getValueYear2();
} else {
return getValueYear3();
}
}
}
}
Class ModelCar:
import java.util.Scanner;
public class ModelCar extends Car {
private int doors;
Scanner scanner = new Scanner(System.in);
public int getDoors() {
return doors;
}
public void setDoors(int doors) {
this.doors = doors;
}
public void doors(){
System.out.println("Insira a quantidade de portas:");
setDoors(this.doors = scanner.nextInt());
}
public void printDoor(){
System.out.println("Quantidade de portas: "+ this.getDoors());
}
}
Main:
public class Main {
public static void main(String[] args) {
Car car = new Car();
ModelCar model = new ModelCar();
car.printCar();
model.doors();
car.printValue();
car.printall();
model.printDoor();
}
}
Obs: tive um problema com relação ao menor número, eu sempre dou os exemplos de valor de "4000, 5000, 10.000" e sempre me mostra que o menor valor é o de 5000, por que?