i'm doing an exercise where i have that to store objects in the array, the problem is when i'm going to print the objects of the array, dont shows the values of type String, the output is:
AFGH
3
5
2
3
5
5
1
2
5
7
my code is:
public static void main(String[] args){
Bill[] billsList = new Bill[5];
Scanner scanner = new Scanner(System.in);
String productCode = " ";
int kilos = 0;
int price = 0;
for(int i = 0; i < billsList.length; i++) {
System.out.println("Digit the code of the product: ");
productCode = scanner.nextLine();
scanner.nextLine();
System.out.println("Digit the kilos sold: ");
kilos = scanner.nextInt();
System.out.println("Digit the price: ");
price = scanner.nextInt();
Bill bills = new Bill(productCode,kilos,price);
billsList[i] = bills;
}
for(int i = 0; i < billsList.length; i++) {
System.out.println(billsList[i]);
System.out.println(billsList[i]);
System.out.println(billsList[i]);
}
}
the code of the class Bill is this:
public class Bill {
private String productCode;
private int kilosSold;
private int price;
public Bill(String productCode,int kilosSold,int price) {
this.productCode = productCode;
this.kilosSold = kilosSold;
this.price = price;
}
}