Siemanko, mam zadanie domowe do zrobienia z wykorzystaniem dziedziczenia oraz rzutowania w dół. Oto moje 3 następujące klasy.
public class Bank {
LinkedList<Client> ListOfClients = new LinkedList<Client>();
public void addClient(Client arg){
ListOfClients.add(arg);
}
public void getClients(){
for(Client c : ListOfClients)
System.out.printf("Name: %s \nSurname: %s \nPESEL: %s\n", c.name, c.surname, c.PESEL);
}
}
public class Client {
LinkedList<Account> ListOfAccounts = new LinkedList<Account>();
public void addAccount(Account args){
ListOfAccounts.add(args);
}
public void getAccounts(){
for(Account a : ListOfAccounts)
System.out.printf("Number: %s\nBalance: %f\n", a.nr, a.balance);
}
}
public class Person extends Client{
protected String name, surname, PESEL;
public Person(){
System.out.println("Type name: ");
name = input_data();
System.out.println("Type surname: ");
surname = input_data();
System.out.println("Type PESEL number: ");
SocialSecurity = input_data();
}
public String input_data(){
Scanner input = new Scanner(System.in);
String data = input.nextLine();
return data;
}
}
Problem tkwi w mojej klasie Bank, a dokładniej w metodzie getClients wyświetla mi następujący błąd: "name cannot be resolved or is not a field". To samo dla pól surname i PESEL. Wiem, że mogę przenieść te pola do klasy Client i mieć problem z głowy, lecz muszę wykorzystać tutaj rzutowanie w dół oraz górę. Poczytałem trochę o RTTI, ale nie udało mi się znaleźć żadnej solucji dla tego problemu. Wrzucam także zdjęcie zadania, gdyby miało w czymś pomóc. http://gyazo.com/2523c1e7d5ae662d6d8c5210bb44ec37