Assignment 21
Due Friday, December 8 at midnight on Canvas


Assignment 21.1: Social Security Numbers 2 (10 pts)
  • Write a program that reads in a series of numbers from a file
  • The file is called numbers.txt.
  • It uses a loop to read in each number from the file and store each number in an array called numbers.
  • Note: you can assume that the size of the array is know ahead of time to be 10.
  • The program should then call two methods.
  • The first method:
    • The method is named formatSSN
    • It take in a String array variable
    • It alters the String array so that each String element is a properly formatted social security number, in the format XXX-XX-XXXX
    • Hint, use a for loop to iterate through each String in the array
    • This method must call the substring method
    • It returns nothing.
  • The second method:
    • The method is named print
    • It takes in an array of Strings as a parameter
    • It opens a new PrintWriter to write to a file named socials.txt
    • It prints out the array using a for loop to the file
    • It returns nothing
  • Once all of the Strings are converted to a formatted social security number, call the print method to display each of the social security numbers.
  • Copy and paste the starter code below into a new file called Social.java

/*
* @author
* Section info
*/
public class Social {
    
    /**
    * Write your javadoc comment for formatSSN here
    */
public static void formatSSN(String[] numbers){
    return;
}

/**
* Write your javadoc comment for print here
*/
public static void print(String[] numbers){
    return;
}


public static void main(String[] args) {
    //write the program logic here


}


  • Copy and paste the below data into a file called numbers.txt:

555666777
333444555
111888494
333222567
123444555
888999000
111666434
222456333
111222999
456889939

  • Below is the output that your program should give in the file socials.txt:
555-66-6777
333-44-4555
111-88-8494
333-22-2567
123-44-4555
888-99-9000
111-66-6434
222-45-6333
111-22-2999
456-88-9939

Assignment 21.2: Customer Data 2 (10 pts)
  • Write a program that reads in a series of names, along with their gender, from a file.
  • The file is called names.txt.
  • The program uses a loop to read in each name from the file and store each person's title (Mr. or Ms.) + name in an array called customers.
  • Note: you can assume that the size of the array is know ahead of time to be 8.
  • The program should then call two methods.
  • The first method:
    • The method is named capitalizeArray
    • It take in a String array
    • It alters the values in the String array to capitalize all of the letters
    • This method must use a for loop. It cannot call any outside methods that we have not discussed in this class.
    • It returns nothing.
  • The second method:
    • The method is named print
    • It takes in an array of Strings
    • It opens up a new PrintWriter and connects it to a file called customers.txt
    • It prints out the array to the file using a for loop
    • It closes the PrintWriter
    • It returns nothing
  • Once you have filled the customers array with titles and names, call the capitalizeArray method to capitalize all the names in the array.
  • Next, call the print method to display each of the capitalized names in the customers.txt file
  • Copy and paste the starter code below into a new file called Customers.java
/**
 * @author
 *
 */
import java.util.Scanner;
public class Customers
{
    /**
     * Write the javadoc comment for capitalizeArray here
     */
    public static void capitalizeArray(String[] customers)
    {
        return;
    }
    
    /**
     * Write the javadoc comment for printArray here
     */
    public static void printArray(String[] customers)
    {
        return;
    }
    
    public static void main(String[] args)
    {
        //declare your customers array here
        //note, you can assume your array will be of length 8
        String name, gender;
        
        
        //Use a while loop to read in the data from the file
        
        
        //call your two methods
    }
}

  • Copy and paste the below data into a file called names.txt:
Barbara Stanton
F
Timoteo Martinez
M
Grace Gu
F
Xing Xiao
M
Dung Kim
F
Tanya White
F
Alan Ngo
M
Abir Fadel
M
  • Below is the output that your program should give in a file called customers.txt:
MS. BARBARA STANTON
MR. TIMOTEO MARTINEZ
MS. GRACE GU
MR. XING XIAO
MS. DUNG KIM
MS. TANYA WHITE
MR. ALAN NGO
MR. ABIR FADEL