Witam, w momencie kiedy chcę wyświetlić zawartość ArrayList, zamiast znajdujących się w niej wartości program wyświetla np. taką treść: Database@4aa298b7. Gdzie robię błąd?
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;
public class KPiR {
private static final int CALCULATE = 2;
private static final int ADD_PAST = 3;
private static final int ADD_KM = 4;
private static final int PRINT_ALL = 5;
private static final int ADD = 6;
private static final int EXIT = 7;
private static List<Database> base;
private static List<FuelCost> fuelCost;
public static void main(String[] args) {
base = new ArrayList<>();
fuelCost = new ArrayList<>();
int option = 0;
Scanner sc = new Scanner(System.in);
do {
printOptions();
try {
option = sc.nextInt();
sc.nextLine();
}
catch(InputMismatchException exc) {
sc.nextLine();
System.out.println("---------------------");
System.out.println("Dane w nieprawidlowym formacie");
continue;
}
switch (option) {
case CALCULATE:
CALCULATE();
break;
case ADD_PAST:
break;
case ADD_KM:
ADD_KM(sc);
break;
case PRINT_ALL:
PRINT_ALL();
break;
case ADD:
ADD(sc);
break;
case EXIT:
break;
}
}
while (option != EXIT);
sc.close();
}
private static void printOptions() {
System.out.println("---------------------");
System.out.println("Dostepne opcje: ");
System.out.println(CALCULATE + "- obliczenie podatku");
System.out.println(ADD_PAST + "- poprzedni miesiac");
System.out.println(ADD_KM + "- kilometrowka");
System.out.println(PRINT_ALL + "- pokaz wprowadzone dane");
System.out.println(ADD + "- dodaj pozycje ");
System.out.println(EXIT + "- wyjscie z programu");
System.out.println("Wybierz opcje: ");
}
private static void ADD(Scanner sc) {
Database data = new Database();
System.out.println("Podaj numer porzadkowy: ");
data.setID(sc.nextInt());
System.out.println("Podaj nazwe zdarzenia: ");
data.setEvent(sc.next());
System.out.println("Podaj date: ");
data.setDate(sc.next());
System.out.println("Podaj wartosc: ");
data.setValue(sc.nextDouble());
sc.nextLine();
base.add(data);
}
private static void CALCULATE() {
double total = 0.0;
for ( Database data : base ) {
total += data.getValue();
}
System.out.println(total);
}
private static void ADD_KM(Scanner sc) {
FuelCost fuel = new FuelCost();
System.out.println("Podaj ilosc przejechanych kilometrow: ");
fuel.setDistance(sc.nextDouble());
System.out.println("Podaj kwote poniesiona na paliwo: ");
fuel.setFuelCost(sc.nextDouble());
sc.nextLine();
fuelCost.add(fuel);
}
private static void PRINT_ALL() {
System.out.println("--------------------");
System.out.println("Wprowadzone dane: ");
for (Database data: base ) {
System.out.println(data);
}
}
}
public class Database {
private int ID;
private String event;
private String number;
private String date;
private double value;
public Database() {
this.ID = 0;
this.event = "";
this.number = "";
this.date = "";
this.value = 0;
}
public Database(int ID, String event, String number, String date, double value) {
this.ID = ID;
this.event = event;
this.number = number;
this.date = date;
this.value = value;
}
@Override
public String toString() {
return this.ID + " " + this.event + " " + this.number + " " + this.date + " " + this.value;
}
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public String getEvent() {
return event;
}
public void setEvent(String event) {
this.event = event;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
}