A lecturer has a text file which includes a list of students name and final exam marks. Create a Java program which:
- Read all the records from the file
- Sort all the records from the file and
- Exit from application
A lecturer has a text file which includes a list of students name and final exam marks. Create a Java program which:
There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in doing your homework for you.
DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules
Post what you have done so far and someone will help you from there.
import java.util.Scanner;
import java.io.*;
import javax.swing.JOptionPane;
public class WriteFile {
public static void main(String[] args) throws FileNotFoundException, IOException {
FileWriter file = new FileWriter("Student Name and Scores.txt");
//PrintStream output = new PrintStream(new File("output.txt"));
Scanner scan = new Scanner (System.in);
System.out.print("Enter number of Students in Class: ");
int k = scan.nextInt();
PrintWriter output = new PrintWriter(file);
for (int j=1; j <= k; j++){
PrintWriter output1 = new PrintWriter(file);
System.out.print("Enter Student First Name: ");
String Name = scan.next();
output.print(Name);
output.print(" ");
System.out.print("Enter Student Last Name: ");
String lastName = scan.next();
output.print(lastName);
output.print('\t');
System.out.print("Enter Student Scores: ");
double score = scan.nextDouble();
output.print(score);
output.print('\n');
}
output.close();
System.out.println("Names and Scores are entered");
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class ReadData {
public static void main (String [] args) throws FileNotFoundException {
try {
File file = new File("Student Name and Scores.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
That is what i have done so far, i dont know how i want to sort them according to the numbers input by the user.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.