In: Computer Science
In this Java lab, you use the flowchart and pseudocode found in the figure below to add code to a partially created Java program. When completed, college admissions officers should be able to use the Java program to determine whether to accept or reject a student, based on his or her test score and class rank. Declare the variables testScoreString and classRankString. Write the interactive input statements to retrieve: A student’s test score (testScoreString) A student's class rank (classRankString) Write the statements to convert the string representation of a student’s test score and class rank to the integer data type (testScore and classRank, respectively).
these are there few line of code as per your requirements: Taking input interactively from user in string form and converting the string representation into integer data type.
Raw_code:
import java.util.Scanner; // import java utility Scanner for
user input
import java.lang.NumberFormatException; // import
NumberFormatException for Invalid user input
// driver class
public class rank{
// main method
public static void main(String[] args){
// creating object of Scanner
Scanner snr = new Scanner(System.in);
// declaring required variables for storing user input
String testScoreString, classRankString;
// variables for storing user input into integer type
int testScore = 0, classRank = 0;
// asking user to enter the TestScore
System.out.print("Enter the TestScore : ");
// using nextLine() method of Scanner object to read input
String
// and storing it in testScoreString
testScoreString = snr.nextLine();
// asking user to enter the classRank
System.out.print("Enter the ClassRank : ");
// using nextLine() method of Scanner object to read input
String
// and storing it in testScoreString
classRankString = snr.nextLine();
// try statement to catch invalid user input
try{
// converting String to integer type by using parseInt method in
Integer wrapper class
testScore = Integer.parseInt(testScoreString);
classRank = Integer.parseInt(classRankString);
}
// catch statement to catch NumberFormatException
catch (NumberFormatException err){
System.out.println("Invalid input!");
// exiting program
System.exit(0);
}
// printing output for debugging
System.out.println("TestScore : " + testScore + ", ClassRank : "+
classRank);
}
}