Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  1. 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

LO5 Illustrate the steps in developing a base pay system.

Answered: 1 week ago