Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A. Create a program that allows a user to input customer records (ID number, fir

ID: 3844115 • Letter: A

Question

A. Create a program that allows a user to input customer records (ID number, first name, last name, and balance owed) and save each record to a file. Save the program as WriteCustomerList.java. When you execute the program, be sure to enter multiple records that have the same last name because you will search for repeated first names in part d of this exercise.

B. Write an application that reads the file created by the WriteCustomerList application and displays the records. Save the file as DisplaySavedCustomerList.java.

C. Write an application that allows you to enter any ID number, reads the customer data file created in Exercise "a", and displays the data for the customer. Display an appropriate message if the ID number cannot be found in the input file. Save the file as DisplaySelectedCustomer.java

D. Write an application that allows you to enter any last name and display all the data for the customers with the given last name. Display an appropriate message if the name cannot be found in the input file. Save the file asDisplaySelectedCustomersByName.java.

Explanation / Answer

Customer.java

package com.koti.chegg;

public class Customer {

   int idNumber;
   String firstName;
   String lastName;
   double balance;

   public Customer(int idNumber, String firstName, String lastName,
           double balance) {
       this.idNumber = idNumber;
       this.firstName = firstName;
       this.lastName = lastName;
       this.balance = balance;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   public String toString() {
       return idNumber + "," + firstName + "," + lastName + "," + balance;
   }

}

***************************************************

package com.koti.chegg;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

1)public class CustomerTest {
  
   public static void main(String[] args) throws IOException {
      
       BufferedWriter writer=new BufferedWriter(new FileWriter(new File("D:/customer.txt")));
       for(int i=0;i<5;i++)
       {
           Scanner scanner=new Scanner(System.in);
           System.out.println("enter customer id number");
           int id=scanner.nextInt();
           System.out.println("enter customer fname");
           String fname=scanner.next();
           System.out.println("enter customer lname");
           String lname=scanner.next();
           System.out.println("enter the balance");
           double bal=scanner.nextDouble();
           Customer c=new Customer(id,fname,lname,bal);
           writer.write(c.toString());
           writer.flush();
           writer.newLine();
          
          
       }
      
   }

}

**************************************************************************************************

2)

package com.koti.chegg;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class DisplaySelectedCustomer {

   public static void main(String[] args) throws IOException {

       Scanner scanner = new Scanner(System.in);
       System.out.println("enter customer id to search");
       int cid = scanner.nextInt();

       BufferedReader reader = new BufferedReader(new FileReader(new File(
               "D:/customer.txt")));

       String line = null;

       while ((line = reader.readLine()) != null) {
           String[] words = line.split(",");
           if (cid == (Integer.parseInt(words[0]))) {
               System.out.println(line);
           }

       }

   }

}

******************************************************************

package com.koti.chegg;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class SavedCustomerList {
  
   public static void main(String[] args) throws IOException {
      
       BufferedReader reader=new BufferedReader(new FileReader(new File("D:/customer.txt")));
      
       String line=null;
      
       while((line=reader.readLine())!=null)
       {
           System.out.println(line);
       }
      
   }

}

************************************************************************************************************

3)

package com.koti.chegg;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class DisplaySelectedCustomerLastName {

   public static void main(String[] args) throws IOException {

       Scanner scanner = new Scanner(System.in);
       System.out.println("enter customer last name to search");
       String lname = scanner.next();

       BufferedReader reader = new BufferedReader(new FileReader(new File(
               "D:/customer.txt")));

       String line = null;

       while ((line = reader.readLine()) != null) {
           String[] words = line.split(",");
           if (lname.equals((words[2]))) {
               System.out.println(line);
           }

       }

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote