Need help coding this assignment. Write the program that allows users to enter t
ID: 3913090 • Letter: N
Question
Need help coding this assignment.
Write the program that allows users to enter the file name to store the information of students then provides the menu to allow users to select the following tasks and only terminate the program when users select exit Each task has to be handle in a user-defined function 1. 2. 3. 0. GRADING STUDENTS Enter Information of Students in class Enter the scores of Students Grading Exit TASK 1: ENTER INFORMATION OF STUDENTS IN CLASS -Open the file with the above file name as output file -Read information of one student that includes: student id, last name, first name, phone Store the information to the output file in the following format id,lastname,firstname,phone then allow users to continue to input the information of other students until users want to stop For example in the output file: 1234567,Le, Liem,2147255796 2222222,Smith,James,4691234567 3124567,David,Kevin,9727654321Explanation / Answer
Code :
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static void se(File f1)throws IOException {
Scanner sc = new Scanner(System.in);
int q= 1;
FileWriter out = new FileWriter(f1);
while(true)
{
System.out.println("Enter ID");
String ID = sc.nextLine();
System.out.println("Enter last name");
String lastname = sc.nextLine();
System.out.println("Enter first name");
String firstname = sc.nextLine();
System.out.println("Enter phone");
String phone = sc.nextLine();
out.write(ID+"," + lastname + "," + firstname + "," + phone + " ");
System.out.println("Enter 1 to continue 2 to exit");
q = sc.nextInt();
String gb = sc.nextLine();
if(q == 2)
break;
}
out.close();
}
static void marks(String filename)throws Exception
{
Scanner sc = new Scanner(System.in);
String gb;
File in = new File(filename +".txt");
Scanner reader = new Scanner(in);
String line;
while (reader.hasNextLine()) {
line = reader.nextLine();
String st[] = line.split(",");
String Quizzes;
String Homeworks;
String Labs, Test,Project, Discussion,teamwork, ExtraCredit;
System.out.println("you want to enter the score of Student with id :"+ st[0]+ "(Y//N)");
char conf= sc.nextLine().charAt(0);
if(conf == 'Y')
{
while(true){
System.out.println("Enter the scors");
System.out.print("1.Quizzes 2.Homeworks 3.labs 4.Test 5.Project 6.Discussion 7.teamwork 8.ExtraCredit 0.exit enter your choice: ");
int choice = sc.nextInt();
gb = sc.nextLine();
if(choice == 0)
{
break;
}
switch(choice)
{
case 1 : Quizzes = sc.nextLine();
break;
case 2 :
Homeworks = sc.nextLine();
break;
case 3 :
Labs = sc.nextLine();
break;
case 4 :
Test = sc.nextLine();
break;
case 5 :
Project = sc.nextLine();
break;
case 6 :
Discussion = sc.nextLine();
break;
case 7 :
teamwork = sc.nextLine();
break;
case 8:
ExtraCredit = sc.nextLine();
}
}
String[] Q = Quizzes.split(" ");
String[] hm = Homeworks.split(" ");
String[] l = Labs.split(" ");
String[] t = Test.split(" ");
String[] p = Project.split(" ");
String[] d = Discussion.split(" ");
String[] tw = teamwork.split(" ");
String[] ec= ExtraCredit.split(" ");
File fw = new File(filename + ".txt");
FileWriter out = new FileWriter(fw);
out.write(st[0]+"," + st[1] + "," + st[2] + "," + st[3] + " ");
// writing the contents of above created arrays inside the file.
out.flush();
out.close();
}
}
}
public static void main(String[] args)throws Exception
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter File name");
String filename = sc.nextLine();
File f1 = new File(filename +".txt");
if (f1.createNewFile()){
System.out.println("File is created!");
}
se(f1);
marks(filename);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.