(początkujący) Siemka :) . Znajdź osobę z największym dochodem. Czyli konsola ma wypisac np: Najwyższy dochód: Kazimierz Stonoga 4500. Klasy obiekty tablice wszystko sam stworzyłem tylko zostało jeszcze znaleźć delikwenta co najwięcej zarabia.
Stworzyłem w klasie Student i Employee metodę o tej samej nazwie getIncome, ale różnych argumentach, czy można jej jakoś użyć do rozwiązania tego zadania ? Czy zrobić to jakoś inaczej ?
public class Person {
String name;
String surname;
long pesel;
String city;
public Person(String name, String surname, long pesel, String city) {
this.name = name;
this.surname = surname;
this.pesel = pesel;
this.city = city;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public long getPesel() {
return pesel;
}
public String getCity() {
return city;
}
public String toString(){
return name + " " + surname + ", PESEL: " + pesel + " city: " + city;
}
}
public class Employee extends Person {
String position;
int salary;
public Employee(String name, String surname, long pesel, String city, String position, int salary) {
super(name, surname, pesel, city);
this.position = position;
this.salary = salary;
}
public String getPosition() {
return position;
}
public int getSalary() {
return salary;
}
public int getIncome() {
return salary;
}
@Override
public String toString(){
return name + " " + surname + ", PESEL: " + pesel + " city: " + city + " position: " + position + " salray: " + salary + " PLN";
}
}
public class Student extends Person {
int group;
int scholarship;
public Student(String name, String surname, long pesel, String city, int group, int scholarship) {
super(name, surname, pesel, city);
this.group = group;
this.scholarship = scholarship;
}
public int getGroup() {
return group;
}
public int getScholarship() {
return scholarship;
}
public int getIncome() {
return scholarship;
}
@Override
public String toString() {
return name + " " + surname + ", PESEL: " + pesel + " city: " + city + " group: " + group + " scholarship: " + scholarship + " PLN";
}
}
public class Test {
public static void main(String[] args) {
Person [] persons = new Person[4];
persons[0] = new Student("Maciek", "Szczebla", 98012238475L, "Wrocław", 2, 750);
persons[1] = new Student("Wojtek", "Okno", 98122557204L, "Bytom", 1, 650);
persons[2] = new Employee("Albert", "Wiatr", 78031139475L, "Hel", "Fisherman", 4000);
persons[3] = new Employee("Kazimierz", "Stonoga", 66092929364L, "Lublin", "Fireman", 4500);
for (Person p : persons){
System.out.println(p);
}
}
}
scibi_92scibi_92scibi_92p_agonjuz wpisalem do IDE. Dobra zostaw jak jest
:]