- Users are requesting the codes...
- See all requests
Try & Catch block problem
The only issue I am having is getting the try & catch blocks to work. The code is required to notify the users when wrong input is entered. But it doesn't work
import java.io.*;
import java.nio.file.StandardOpenOption.*;
import java.nio.file.*;
import java.util.*;
class StudentsStanding {
public static void main(String [] args) throws IOException {
Path probationListPath = Paths.get("Probation.txt");
Path fullProbationListPath = probationListPath.toAbsolutePath();
Path goodStandingListPath = Paths.get("GoodStanding.txt");
Path fullGoodStandingListPath = goodStandingListPath.toAbsolutePath();
Path deansListPath = Paths.get("DeansList.txt");
Path fullDeansListPath = deansListPath.toAbsolutePath();
OutputStream probationList = new BufferedOutputStream(Files.newOutputStream(fullProbationListPath));
OutputStream goodStandingList = new BufferedOutputStream(Files.newOutputStream(fullGoodStandingListPath));
OutputStream deansList = new BufferedOutputStream(Files.newOutputStream(fullDeansListPath));
InputStream probation = new BufferedInputStream(Files.newInputStream(probationListPath));
BufferedReader probationReader = new BufferedReader(new InputStreamReader(probation));
InputStream goodStanding = new BufferedInputStream(Files.newInputStream(goodStandingListPath));
BufferedReader goodStandingReader = new BufferedReader(new InputStreamReader(goodStanding));
InputStream deans = new BufferedInputStream(Files.newInputStream(deansListPath));
BufferedReader deansReader = new BufferedReader(new InputStreamReader(deans));
Scanner input = new Scanner(System.in);
int numStudents;
String[] firstName, lastName, idNumber;
double[] GPA;
System.out.println("How many student's would you like to register?");;
numStudents = input.nextInt();
firstName = new String[numStudents];
lastName = new String[numStudents];
idNumber = new String[numStudents];
GPA = new double[numStudents];
int counter = 0;
boolean isDeansList = false;
boolean successful = false;
try {
for(int i = 0; i < firstName length; i++) {
System.out.println("Now adjusting student # " + (i+1));
System.out.println("First name: ");
input.nextLine(); [removed]input.nextLine().toUpperCase();
System.out.println("Last name: "); [removed]input.nextLine().toUpperCase();
System.out.println("New ID number: "); [removed]input.nextLine();
System.out.println("GPA: "); [removed]input.nextDouble();
}
String s = "";
byte[] toBytes;
String writeToProbationFile, writeToDeansFile, writeToGoodStandingFile;
System.out.println("---Students entered---\n");
for(int [removed]0; i < firstName.length; i++) {
if(GPA[i] [removed]2.0) {
System.out.println("Students on Academic Probation:");
break;
}
}
for(int [removed]0; i < firstName.length; i++) {
if(GPA[i] [removed]2.0) {
writeToProbationFile = "First name: " + firstName[i] + "\nLast Name: " + lastName[i] + "\nID #: " + idNumber[i] +"\nGPA: "+ GPA[i] +"\n\n"; [removed]writeToProbationFile.getBytes();
System.out.println("Student: " + firstName[i] + " " + lastName[i] + "\nID number: " + idNumber[i] + "\nGPA: " + GPA[i] + "\n");
probationList.write(toBytes);
}
}
for(int [removed]0; i < firstName.length; i++) {
if(GPA[i]> 2.0) {
System.out.println("Students in Good Standing");
break;
}
}
for(int i = 0; i < firstName.length; i++) {
if(GPA[i] >= 3.5)
isDeansList = true;
if(GPA[i] > 2.0){
writeToGoodStandingFile = "First Name: " + firstName[i] + "\nLast Name: " + lastName[i] + "\nID #: " + idNumber[i] +"\nGPA: "+ GPA[i] +"\n\n";
toBytes = writeToGoodStandingFile.getBytes();
System.out.println("Student: " + firstName[i] + " " + lastName[i] + "\nID number: " + idNumber[i] + "\nGPA: " + GPA[i] + "\n");
goodStandingList.write(toBytes);
counter++;
}
}
probationList.close();
goodStandingList.close();
String[] readFirst = new String[counter];
String[] readLast = new String[counter];
String[] readID = new String[counter];
String[] readGPA = new String[counter];
int counter1 = 0;
double GPARead = 0;
String first = "", last = "", id = "";
double GPAKeeper = 0.0;
if(isDeansList) {
System.out.println("---Deans list---");
while((s = goodStandingReader.readLine()) != null) {
if(s.startsWith("First Name: ")) {
first = s.substring(12);
}
else if(s.startsWith("Last Name: ")) {
last = s.substring(11);
}
else if(s.startsWith("ID #: ")) {
id = s.substring(6);
}
else if(s.startsWith("GPA: ")) {
GPAKeeper = Double.parseDouble(s.substring(5));
if (GPAKeeper >= 3.5) {
System.out.println("Student: " + first + " " + last + "\nID #: " +
id + "\nGPA: " + GPAKeeper);
}
}
counter++;
}
}
}
catch(InputMismatchException e) {
System.out.println("Wrong output");
}
probationReader.close();
goodStandingReader.close();
deansReader.close();

1
# Users who requested
the code (so far)

$15
Suggested price from buyers
at which they’d buy

$15
Potential revenues from requesters (actual
revenues can be significantly higher)
Time of last request:on Feb 21, 2018
Tags:java
Sellers
If you own such codes, please set up an offer and then invite users to it by clicking on «Invite to offer».
Invite to offerBuyers
If you’re also be willing to buy those codes then click on «I’d also buy it» (no commitment to buy, but please only click when you’re serious about it).
I'd also buy it!Tell people about Sellcodes and get 20-40% on every resulting sale!