Question

In: Computer Science

IN JAVA: Write a simple program that takes 5 inputs from the user and save them...

IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.

Solutions

Expert Solution

 package fileio; import java.io.*; import java.util.Scanner; public class Fileio { public static void append(String fn,String str) throws IOException{ //function to append the details of the student BufferedWriter out = new BufferedWriter(new FileWriter(fn, true)); out.write(str+'\n'); out.close(); } public static void main(String[] args) throws IOException { Scanner s=new Scanner(System.in); String sname,sadd,sdob; System.out.println("Enter Student Name: "); sname=s.nextLine(); System.out.println("Enter Student Address: "); sadd=s.nextLine(); System.out.println("Enter Student DOB: "); sdob=s.nextLine(); System.out.println("Storing in the File...."); BufferedWriter bf=new BufferedWriter(new FileWriter("myfile.txt")); //making the use of Buffered Writer to write in a file bf.write(sname+'\n'); bf.close(); append("myfile.txt",sadd); append("myfile.txt",sdob); System.out.println("Printing the File..."); BufferedReader in = new BufferedReader(new FileReader("myfile.txt")); //Similarly for reading using Buffered Reader class String mystring; while ((mystring = in.readLine()) != null) { System.out.println(mystring); } } }

Here the above program demonstrates the task which was required to be done in the above question using Java. Also the screenshot of the output is being attached for any further reference. Hope it helps....


Related Solutions

Write a Java program that takes an array of 10 "Int" values from the user and...
Write a Java program that takes an array of 10 "Int" values from the user and determines if all the values are distinct or not. Return TRUE if all the values of the array are distinct and FALSE if otherwise.
Write a java program that asks the user for a number n and gives them the...
Write a java program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n. Example of running this program: Enter an integer number n: __7________ Enter Sum or Product: __Sum__________________________________ Program output: Sum of 1 ... 7 Sum or Product: Sum Sum = 28 Now second sample of second execution Enter an integer number n: __5__________________________________ Enter Sum or Product: __Product__________________________________ Program output:  Product of 1...
in Java, write a program that takes an input of 4 numbers and splits them into...
in Java, write a program that takes an input of 4 numbers and splits them into 4 separate lines. EXAMPLE: so if input is 1994 the output should be 1 9 9 4
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a short, java program that interacts with the user asking them to buy an xbox...
Write a short, java program that interacts with the user asking them to buy an xbox series x or PS5 and does the following: create at least 2 double variables create at least 1 constant get at least 1 string input from the user get at least 1 int/double input from the user include both, incorporating the input you got from the user: 1 multiway if-else with at least 3 "else if" 1 nested if Your program should combine all...
Write a java simple document retrieval program that first asks the user to enter a single...
Write a java simple document retrieval program that first asks the user to enter a single term query, then goes through two docuements named doc1.txt and doc2.txt (provided with assignment7) to find which document is more relevant by calculating the frequency of the query term in each document. Output the conclusion to a file named asmnt7output.txt in the following format (as an example for query “java” and “problem”). The percentages in parenthese are respective supporting frequencies. java: doc1(6.37%) is more...
Write a simple JAVA program to understand natural language. The user will enter the input following...
Write a simple JAVA program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Chris came to Bangkok, Thailand in 2009. The user will follow the exactly the same formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay in City for X year(s). City is in...
Develop a Java program for this problem where the user inputs an Earth age and the...
Develop a Java program for this problem where the user inputs an Earth age and the program will then display the age on Mercury, Venus, Jupiter, and Saturn. The values for d are listed in the table. Planet d = Approximate Number of Earth Days for This Planet to Travel Around the Sun Mercury 88 Venus 225 Jupiter 4380 Saturn 10767
how to write a cpp program that takes a number from a user, and print the...
how to write a cpp program that takes a number from a user, and print the sum of all numbers from one to that number on screen? using loop interation as basic as possible.
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT