Answered step by step
Verified Expert Solution
Question
1 Approved Answer
whats wrong with my code: / * * Click nbfs: / / nbhost / SystemFileSystem / Templates / Licenses / license - default.txt to change
whats wrong with my code:
Click nbfs:nbhostSystemFileSystemTemplatesLicenseslicensedefault.txt to change this license
package cpanlabstarter;
import java.ioBufferedReader;
import java.ioFile;
import java.ioFileReader;
import java.ioFileWriter;
import java.ioIOException;
public class Main
public static void mainString args
final int size ;
Professor professors new Professorsize;
Student students new Studentsize;
int pInt ;
int sInt ;
try
FileReader fr new FileReadernew FilePeopletxt;
BufferedReader br new BufferedReaderfr;
String line;
while line brreadLine null
String parts line.split;
String title parts;
String name parts;
String major parts;
System.out.printlntitle;
System.out.printlnname;
System.out.printlnmajor;
if titleequalsProfessor
String department parts;
professorspInt new Professortitle name, department;
else if titleequalsStudent
String degree parts;
studentssInt new Studenttitle name, degree;
brclose;
frclose;
catch IOException e
System.out.printlnProfessors:;
for int i ; i pInt; i
System.out.printlnprofessorsi;
System.out.println
Students:";
for int i ; i sInt; i
System.out.printlnstudentsi;
writeToFileprofessors pInt, "Professor.txt;
writeToFilestudents sInt, "Student.txt;
private static void writeToFilePerson people, int count, String fileName
try
FileWriter w new FileWriterfileName;
for int i ; i count; i
wwritepeopleitoString
;
wclose;
catch IOException e
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started