Question

Please run the program and show the result with screenshots after. Thank you (Java Eclipse) Customer...

Please run the program and show the result with screenshots after. Thank you (Java Eclipse)

Customer Data: Area Codes

  • Assume you work for a company that tracks customer information, including name, gender and phone numbers
  • Your company has a file called customers.txt which contains the following information:

Jiming Wu
F
4082123458
James Brown
M
8315678432
Leanna Perez
F
4087654433
Xing Li
M
8313214555
Stacey Cahill
O
8312123333
Mohammed Abbas
M
4083134444
Kumari Chakrabarti
F
4086667777
Shakil Smith
M
4082123333
Jung Ahrin
F
8319257788
Pedro Martinez
M
4086162323
Ally Gu
O
4089256776
Tamara White
F
8317778978
Alvin Ngo
M
4089256677
Abir Fadel
M
8316645325
Brad Feinman
M
8312023443
Xiaohang Yue
M
8318990033

  • Half of the 16 customers in this file have a phone number with an 831 area code.
  • Half have a phone numbers have a 408 area code.
  • Write a program that reads in all of the customer information using a loop, and stores the names of the customers in two different string arrays - each array of length 8.
  • One array should store the customers with a 408 area code and one array should store the customers with an 831 area code.
  • When the customers are stored in each array, they should be stored as Mr., Ms. or Mx. depending on the gender below their name in the file.
  • In other words, whenever the customers.txt file contains an M below the customer name, you should place the word Mr. before the name.
  • Whenever the customers.txt file contains an F below the customer name, you should place the word Ms. before the name.
  • Finally, whenever the file contains an O below the customer name, you should place the word Mx. before the name.
  • You must also capitalize each name by calling the capitalizeName method.
  • I recommend calling capitalizeName before storing the name inside the array.
  • Finally, you will be required to write the two arrays to a file.
  • Each array should be written to a different file.
  • The 408 area code array should be written to a file called SJCustomers.txt
  • The 831 area code array should be written to a file called SCCustomers.txt
  • You must write the arrays to the file by calling the printArray method.
  • Note that you will need to call printArray twice - once for each array.
  • Important: Your solution must only use concepts and methods covered in this class to receive credit.

Method requirements

  • capitalizeName Method:
    • The method is named capitalizeName

    • It take in an array of Strings

    • It capitalizes all of the letters in each String of the array

    • This method must use a for loop. It cannot call any outside methods that we have not discussed in this class.

    • It returns nothing.

  • printArray Method:
    • The method is named printArray
    • It throws IOException
    • It takes in two parameters:
      • the first parameter is an array of Strings,
      • the second parameter is a String for the name of a text file in which to write out the data
    • The method must open the file whose name is passed in as a parameter
    • It declares a PrintWriter and uses it to write to the specified file
    • It uses a for loop to print out the contents of the array in the file, with each element on its own line
    • It then closes the PrintWriter.
    • It returns nothing.
  • On the final, you will be required to write a the complete method, including its signature, and a Javadoc comment for each method
  • The method signature is provided below but will not be provided on the final.
  • Copy and paste the starter code below into a new class called AreaCodes.java


/*
* @author
* CIS 36A
*/
import java.io.*;
import java.util.Scanner;

public class AreaCodes {
  
   public static void main(String[] args) throws IOException {
       String name, gender, phone;

        //Declare your two arrays here - one per area code
      

        //Declare File and Scanner

        //Below variables to keep track of array index in loop

       int i = 0;
       int j = 0;
       while(??????) {

            //read in name and gender

          

            //if statements related to gender

          

            //read in phone

          

            //if statements for phone

          
       }

        //call capitalizeNames method twice

      

        //call printArray method twice

        //close Scanner

      
   }

    

          //write Javadoc comment here

   public static void capitalizeNames(String[] names) {

        return;

   }

    

          //write Javadoc comment here

   public static void printArray(String[] names, String fileName){//throw IOException

       return;

   }
}

  • Below is the output that your program should give inside of the SJCustomers.txt file

MS. JIMING WU
MS. LEANNA PEREZ
MR. MOHAMMED ABBAS
MS. KUMARI CHAKRABARTI
MR. SHAKIL SMITH
MR. PEDRO MARTINEZ
MX. ALLY GU
MR. ALVIN NGO

  • It should also give the below is the output in a second file called SCCustomers.txt file

MR. JAMES BROWN
MR. XING LI
MX. STACEY CAHILL
MS. JUNG AHRIN
MS. TAMARA WHITE
MR. ABIR FADEL

MR. BRAD FEINMAN

MR. XIAOHANG YUE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Following is the complete code for the above problem:

/*
* @author
* CIS 36A
*/
import java.io.*;
import java.util.Scanner;

public class AreaCodes {
  
public static void main(String[] args) throws IOException {
String name, gender, phone;

//Declare your two arrays here - one per area code
String[] names_408 = new String[8];
String[] names_831 = new String[8];

//Declare File and Scanner
File f = new File("customers.txt");
Scanner scan = new Scanner(f);
//Below variables to keep track of array index in loop

int i = 0;
int j = 0;
while(scan.hasNextLine()) {

//read in name and gender
      name = scan.nextLine();
      gender = scan.nextLine();
      String prefix = null;

//if statements related to gender
      if(gender.equals("M") || gender.equals("m")) {
          name = "mr. " + name;   
      }else if(gender.equals("F") || gender.equals("f")) {
          name = "ms. " + name;   
      }else {
          name = "mx. " + name;   
      }
  

//read in phone
      phone = scan.nextLine();
  

//if statements for phone
      if(phone.startsWith("408")) {
          names_408[i++] = name;
      }else {
          names_831[j++] = name;
      }
  
}

//call capitalizeNames method twice
capitalizeNames(names_831);
capitalizeNames(names_408);

//call printArray method twice
printArray(names_408, "SJCustomers.txt");
printArray(names_831, "SCCustomers.txt");
//close Scanner
scan.close();
  
}

  

//write Javadoc comment here

public static void capitalizeNames(String[] names) {
   for(int i = 0;i<names.length;i++) {
       names[i] = names[i].toUpperCase();
   }
return;
}

  

//write Javadoc comment here

public static void printArray(String[] names, String fileName) throws IOException{//throw IOException
   FileWriter fw = new FileWriter(new File(fileName));
   for(int i = 0;i<names.length;i++) {
       String line = names[i] + "\n";
       fw.write(line);
//System.out.println(line);
   }
   fw.close();
return;
}
}

After running the following program with the given file, the output file are as follows:

Area Codes,javacustomers.tvtSCCustomers.tSCustomers.tbot 1 MR. JAMES BROWN 2 MR. XING LI 3 MX. STACEY CAHILL 4 MS. JUNG AHRINAreaCodsjava customers.tt SCCustomers.tt SJCustomers.txt 3 İhs. JIMING WU 2 MS. LEANNA PEREZ 3 MR. MOHAMMED ABBAS 4 MS. KUMAR

If you have any problem regarding the understanding of the solution, do let me know in the comment section.
Don't forget to like the solution, it really means a lot.
Thanks

Add a comment
Know the answer?
Add Answer to:
Please run the program and show the result with screenshots after. Thank you (Java Eclipse) Customer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab 1.4: Arrays, File I/O and Method Review (40 pts) Assume you work for a company...

    Lab 1.4: Arrays, File I/O and Method Review (40 pts) Assume you work for a company that received a list of email addresses of potential new customers from a data broker. Your company receives a file named customers.txt with the below information: Jiming Wu [email protected] James Brown [email protected] Leanna Perez [email protected] Xing Li [email protected] Stacey Cahill [email protected] Mohammed Abbas [email protected] Kumari Chakrabarti [email protected] Shakil Smith Shakattaq2G.com Jung Ahrin [email protected] Pedro Martinez [email protected] Ally Gu [email protected] Tamara White [email protected] Alvin Ngo...

  • User Profiles Write a program that reads in a series of customer information -- including name,...

    User Profiles Write a program that reads in a series of customer information -- including name, gender, phone, email and password -- from a file and stores the information in an ArrayList of User objects. Once the information has been stored, the program should welcome a user and prompt him or her for an email and password The program should then use a linearSearch method to determine whether the user whose name and password entered match those of any of...

  • Write a Java program to read customer details from an input text file corresponding to problem...

    Write a Java program to read customer details from an input text file corresponding to problem under PA07/Q1, Movie Ticketing System The input text file i.e. customers.txt has customer details in the following format: A sample data line is provided below. “John Doe”, 1234, “Movie 1”, 12.99, 1.99, 2.15, 13.99 Customer Name Member ID Movie Name Ticket Cost Total Discount Sales Tax Net Movie Ticket Cost Note: if a customer is non-member, then the corresponding memberID field is empty in...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • These are the instructions for a java file. We have not learned array of string or...

    These are the instructions for a java file. We have not learned array of string or anything that complex. I am trying to solve this possibly using the IndexOf method. 13.4 Assignment 4: Formal Name Generator Complete the generateFormalName method so that... you return the formal name (Mr. or Ms. + last name) given a full name and gender (Strings) as parameters. --You can assume a valid name & gender (any case allowed) is passed in. Example 1: ("Bob Smith",...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • I need the following written in Java please, thank you ' We want you to implement...

    I need the following written in Java please, thank you ' We want you to implement a java class that will show details on users and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your User class: - A private String firstName that specifies the first name of the user - A private String lastName that specifies the last name of the user - A private int age that specifies user's age...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • Need code written for a java eclipse program that will follow the skeleton code. Exams and...

    Need code written for a java eclipse program that will follow the skeleton code. Exams and assignments are weighted You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/MIS 207 by inputting their scores obtained on worksheets, assignments and exams into the program. A skeleton code named GradeCompute.java containing the main method and stubs for a few other methods, is provided to you. You must not modify/make changes...

  • Java Description This project is designed to help you practice for the second midterm examination. First...

    Java Description This project is designed to help you practice for the second midterm examination. First you will hand write the code for the project, just as you would do on the examination. Then you will take your hand written code and enter it into eclipse and debug/fix it. This should help you identify challenges that you have in hand writing code that could cause problems on the midterm on Wednesday Write a program that generates platitudes, by writing each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT