newbie here
Is this the way to populate an ArrayList
with objects(code below)? In the code below I've managed to read the information in the file of my choice and populate it with words. It appears in this format:
App name: Barcode Scanner
Developer name: WizardTech
Function: Scans bar-codes.
Type: Utility
Cost: 7.0
Popularity: 0
========================================================
I want to be able to get the attributes of the objects and use them like any other variable in the code. Is it possible to do this with the code I have right now?
For example, I've got an attribute named 'Cost' which belongs to the object and I want to get that attribute from the object in the ArrayList and use it for a calculation.
Here's the code:
public class c {
public static void wholeSystem3() {
boolean choice = true;
int input6 = 0;
Shop customerConfig = new Shop(new ArrayList<Customer>());
while (choice == true) {
System.out.println("Proceed to Customer creation by entering 1");
Scanner myScan1 = new Scanner(System.in);
input6 = myScan1.nextInt();
if (input6 == 1) {
System.out.println("Enter your information:");
Scanner myScan0 = new Scanner(System.in);
Customer myCustomer = new Customer();
System.out.println("Please enter your name:");
myCustomer.setCustomerName(myScan0.nextLine());
System.out.println("Please enter your address:");
myCustomer.setAddress(myScan0.nextLine());
System.out.println("Please enter your profession:");
myCustomer.setProfession(myScan0.nextLine());
System.out.println(myCustomer.getCustomerName() + " " + myCustomer.getAddress());
customerConfig.addCustomers(myCustomer);
File CustomerList = new File("CustomerList");
try {
BufferedWriter out;
out = new BufferedWriter(new FileWriter(CustomerList, true));
out.write("Customer name:" + myCustomer.getCustomerName());
out.newLine();
out.write("Customer Address:" + myCustomer.getAddress());
out.newLine();
out.write("Customer Profession:" + myCustomer.getProfession());
out.newLine();
//Close the output
out.close();
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
System.out.println("Would you like to immediately purchase an app?");
input6 = myScan0.nextInt();
if (input6 == 1) {
String appStoreFile = "AppStore"; //"AppStore" Name of file I wish to take objects from to populate ArrayList
String line;
ArrayList testList = new ArrayList();
try {
BufferedReader input = new BufferedReader(new FileReader(appStoreFile));
if (!input.ready()) {
throw new IOException();
}
while ((line = input.readLine()) != null) {
testList.add(line);
}
input.close();
} catch (IOException b) {
System.out.println(b);
}
}
}
}
}
}