Exercise 1 — Input information then write to a file
Write an application that will have someone input any number of friends' phone data and write the data to a file.
File Details
The output file should be named "friend1.txt" The data in the files will be last name, first name, age and phone number, each piece of data on a separate line, such as:
Smith
Pete
15
888-1234
Jones
Sue
17
885-4578
Use parallel arrays to create this information before writing the output file.
Please help code this in Java.
package Oct2_2020;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Scanner;
public class WriteToFile {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of friends: ");
int n = sc.nextInt();
String firstNames[] = new String[n];
String lastNames[] = new String[n];
int ages[]=new int[n];
String phones [] = new String[n];
PrintWriter pw = new PrintWriter(new FileWriter("frind1.txt"));
for(int i=0;i<n;i++) {
System.out.println("Enter lastName: ");
lastNames[i]=sc.next();
System.out.print("Enter firstName: ");
firstNames[i]=sc.next();
System.out.print("Enter age: ");
ages[i]=sc.nextInt();
System.out.println("Enter phone: ");
phones[i]=sc.next();
}
for(int i=0;i<n;i++) {
pw.println(lastNames[i]);
pw.println(firstNames[i]);
pw.println(ages[i]);
pw.println(phones[i]);
}
pw.close();
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Exercise 1 — Input information then write to a file Write an application that will have...
Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...
java Write a method named printEntireFile that prompts the user for a file name and points the contents of that file to the console as output. You may assume that the file exists. For example. If the file example. txt contains the following input data: Then the following would be an example dialogue of your method:
Write a program that will take input from a file of numbers of type double and output the average of the numbers in the file to the screen. Output the file name and average. Allow the user to process multiple files in one run. Part A use an array to hold the values read from the file modify your average function so that it receives an array as input parameter, averages values in an array and returns the average Part...
write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...
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...
Lab exercise Computing III 9 1. There is text file (testl.txt) which contains multi-line data including the name "John" at multiple lines as follows. John is a good student. He studies regularly for 8 hours daily and attends to every lecture in school. John wants to be a computer programmer John is also a great sportsman. Open a new file (test2.txt) replacing the name “John" with "Smith" 2. Assume that a text file (text3.txt) stores employee data as follows. 1001,...
4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...
Write a method in JAVA for accepting a text file as input and If the file is of type .txt, then calculate and return the number of words in that txt file. If the file is of type .csv, then return the number of rows and number of columns in that csv file. If the file is of any other type, then return a message stating that file type is not supported. Note: Use StringBuilder wherever applicable.
C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...
Write a program that will first receive as input the name of an input file and an output file. It will then read in a list of names, id #s, and balances from the input file specified (call it InFile.txt) which you will create from the data provided below. The program will then prompt the user for a name to search for, when it finds the name it will output to a file (call it OFile.txt) the person’s id#, name,...