Question: In Java Write a class called Customer that has data fields for ID, age, name and phoneNumber. For the age, name and phoneNumber fields add
- In Java Write a class called Customer that has data fields for ID, age, name and phoneNumber.
- For the age, name and phoneNumber fields add getter and setter methods.
- Specify one constructor to initialise the age, name and phoneNumber field.
- The ID field should automatically be filled in with the next available ID (starting at 1).
- Overwrite the toString method so that it returns a string description for the customer in the format below.
1235 John Smyth, 0861234567, 40
Use the Customer class to implement the Comparable interface and provide implementation of the compareTo method, which will compare two Customer objects by their age.
Write a class called Lab8 that creates 5 customers. Store these customer objects in an ArrayList and then sort the list, using the Collections.sort method. (You will need to import java.util.* for this.)
Loop through the sorted list and print the details of each customer to a new line in a text file. The example below will open/create a text file called OutFile.txt and print the line Test. You will need to either wrap this code in a try/catch block or declare that your main method throws an IOException either is acceptable. (You will need to import java.io.* for this).
PrintWriter out = null;
out = new PrintWriter(new FileWriter("OutFile.txt"));
out.println("Test);
if (out != null) out.close();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
