JAVA - important to follow steps exactly using only intro basic java. STARTER CO
ID: 3906635 • Letter: J
Question
JAVA - important to follow steps exactly using only intro basic java.
STARTER CODE:
* 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
}
}
THIS IS WHAT GOES IN TO names.txt
Barbara Stanton
F
Timoteo Martinez
M
Ally Gu
O
Xing Xiao
M
Dung Kim
F
Tanya White
F
Alan Ngo
M
Abir Fadel
M
Nataly Luna
F
Charles Atkinson
M
Stacey Cahill
O
Stephanie Teatro
F
Ping Li
M
June Park
F
Binh Nguyen
M
Assignment 21.2: Customer Data (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. or Mx.) name in an array called customers Note: you can assume that the size of the array is know ahead of time to be 15 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.javaExplanation / Answer
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
/* this method is used to captilise the names in the array.
*/
public static void capitalizeArray(String[] customers)
{
for(int i=0;i<len(customers);i++){
customers[i] = uppercase(customers[i]);
}
return;
}
/**
* this method was called to print the array names
*/
public static void printArray(String[] customers)
{
for(int i=0;i<len(customers);i++)
System.out.println(customers[i]);
return;
}
class Customers(){
public static void main(String[] args)
{
char Customers[]; //declaring array
Customers = new char[20]; // allocating memory to array
// create Scanner inFile1
Scanner inFile1 = new Scanner(new File("names.txt")).useDelimiter(",\s*");
String name, gender;
// while loop
while(inFile1.hasNext()){
// find next line
Customers = inFile1.next();
temps.add(Customers);
}
inFile1.close();
//calling two methods
capitalizeArray(Customers);
printArray(Customers);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.