Home / Expert Answers / Computer Science / can-anyone-please-help-with-this-code-some-notes-are-given-below-notes-use-notepad-to-make-the-i-pa597

(Solved): Can anyone please help with this code? Some notes are given below NOTES: Use Notepad to make the i ...



Write a Java program that reads a series of strings from an input text file. Each line in the file consists of information ab

Can anyone please help with this code? Some notes are given below

NOTES:

  1. Use Notepad to make the input file.  Put one student’s information per line, in the format specified above. Make certain you don’t have a blank line at the end.
  2. use this to connect to the file, then read from it:

           File file = new File(“students.txt”);  // use the name you gave the file

Scanner input = new Scanner(file);

 

(use the nextLine( ) Scanner method to read the data, as if it was coming from the keyboard, so this statement will work to read one line:

nextStudent = input.nextLine( ); 

 

also use the hasNext( ) method to control the loop that reads from the input file.  It checks for more input in the file – check for end of file. )

 

  1. you must add this phrase to the end of the main( ) method header line, throws IOException so it looks like this (or you can use a try – catch statement for this exception, but it should be OUTSIDE the end-of-file loop)

 

      public static void main( String[ ] args) throws IOException

 

  1. the File and IOException classes are in the java.io library, so you need to have this statement at the beginning of the program

      import java.io.*;

 

  1. add this statement to the end of main

      input.close( );

 

  1. the students.txt file must be in the same folder as this program

 

  1. use this type of syntax for each output file:

PrintWriter validCodes = new PrintWriter(“validInputs.txt”);

validCodes.println(“    “);   or you can use print( )

 

validCodes.close( );  should be at the end of the main( )

 

  1. The String methods PowerPoint contains a summary of various String methods, including examples of how to use them

Thanks.

Write a Java program that reads a series of strings from an input text file. Each line in the file consists of information about one student at the ABC Professional School. The input consists of the following; the items are separated by commas: - the student's first and last name (separated by a blank, followed by a comma) - the student's number (valid numbers are between 1 and 6000 ), and - the student's program of study (one character, either \( \mathrm{C} \) for Computing, B for Business, \( \mathrm{S} \) for Science, or T for Tourism). - this information must be read in as one string using the nextline( ) method, and then broken into the 3 individual data items mentioned in the previous bullets, using the judex.f( ) and substring() methods -see the ProductCodes example. You must use these methods to extract the 3 pieces of information. You are not allowed to use other methods like split() or ysepelimiter(). ets As the code tries to break the string into its parts, exceptions may be thrown. Some are Java exceptions (which ones? see the ProductCodes example in lectures) and some are programmer created exceptions (which ones? the non-Java exceptions like student number and program of study). In particular you must create these exception classes and deal with/catch them in your program, by writing the original input string to the Inyalidinputs output file followed by a detailed description of the problem encountered: - MissingCommaException - this exception will be thrown if the input string doesn't have the 3 parts ( 2 commas). The message you write to the file should be very specific and identify what the input string should look like - InvalidProgramException o state the invalid code and what the valid codes are - InvalidStudentNumberException - state the invalid number and what the valid numbers are Catch these in main( ) and write the input string and a description of the problem encountered to the output file. Be specific. For example rather than outputting, "invalid student number" state that "9789 is an invalid student number". Input a series of these strings from a text file, so that all possible exceptions are tested. (You make up the input data. Make certain you test all possible exceptions that can arise. ? Also include at least 4 valid inputs and write out a message to another output file called Validlaputs. You should write the original input string to this file, followed by a message in this format Name = Pi Di, Program \( = \) Tourism, Student Number \( =9000 \)


We have an Answer from Expert

View Expert Answer

Expert Answer


//ValidateInput.java import java.io.*; import java.util.Scanner; class MissingCommaException extends Exception { private String message; //constructor public MissingCommaException(String str) { this.message = str; } @Override publi
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe