Alexander S-f Ross Alexander S-f Ross - 1 year ago 74
Java Question

Implement a load and list function

I have been given this piece of pre set code by my uni and have been told to implement a load method and a list method from it. However I am currently unsure of how to fill in the blanks. I usually am not to bad at programming however the stress of meeting the deadline has caused me to forget simple little things.This is the final part of the 1st increment of my project.

How would I would implement a load and list method to get the file customers.txt.

public static List<Customer> loadCustomers() {
List<Customer> customers = null;

return customers;

I also have the follwing at the top of my class

public static void main(String[] args) {
Scanner userInput = new Scanner (;
char choice;

List<Customer> customers=loadCustomers();

Answer Source

I am not sure if I understand this correctly. I am guessing there are two different things:

  1. Loading the list of customers from customers.txt into a list
  2. Returning that list of customers back in this method.

To solve this, you will have to analytically solve using these steps:

  1. Open and parse the customers.txt file
  2. For each customer, add them to your customers list
  3. After you have finished reading the last line (or last customer) on your file, close the file, and return the list.

You will have to demonstrate what you have already done in your attempts to solve this question - so I won't post any code yet. But the above workflow tells you how to tackle this question.

Also, not sure why the method signature needs to be static - nothing bad- but why is it an instance method?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download