Help with intro to Java procedure call
I have a school project in Java assigned to do the following:
Write an application to be used in a college admission's office. To be admitted to this school, the student must have either: •A grade point average of 3.0 or higher and an entrance score of 60 or higher •An entrance score of 85 or higher and any grade point average To make things more user friendly, write some code to do some error checking of the data.
That is, if the grade point average is not between 0.0 and 4.0 or if the entrance score is not between 0 and 100, then print an appropriate error message to the screen telling the user that they entered invalid data. Use the above criteria to write a procedure called, accepted, that takes the grade point average and entrance score as parameters and returns no value. This procedure will print either "Accept" or "Reject", accordingly. Finally, write a main procedure that prompts the user for a grade point average and an entrance score. This procedure should then call the acc开发者_运维知识库epted method to display the result.
Although I foolishly wrote the following code below without thoroughly reading the directions. My problem is I am not sure how call a procedure. Also how do I pass variables to this called procedure? Any help or other examples would be helpful. Below is the code I written while it works it doesn't feature an Accept procedure that gets called.
import java.util.Scanner;
class College {
public static void main(String[] args) {
double testGPA;
int testScore;
Scanner input = new Scanner(System.in);
System.out.println("Welcome to Student Admisions");
System.out.println("Please student prospects GPA: ");
testGPA = input.nextDouble();
System.out.println("Now enter prospect students Test Score: ");
testScore = input.nextInt();
System.out.println("-----------------------");
if (testGPA >= 0.0 && testGPA <= 4.0 && testScore >= 0 && testScore <= 100){
if(testGPA >= 3.0 && testScore >= 60 || testScore >= 85){
System.out.println("Student is ACCEPTED to university!");
System.out.println("Students GPA is a " + testGPA + " and students test score is a " + testScore + "%");
}
else {
System.out.println("Student is NOT ACCEPTED to university!");
System.out.println("Students GPA is a " + testGPA + " and students test score is a " + testScore + "%");
}
}
else{
System.out.println("Please Check GPA and Test score input!");
System.out.println("Your inputs were:");
System.out.println(testGPA + " = GPA should be between 0.0 and 4.0.");
System.out.println(testScore + " = Test Score should be between 0 and 100");
}
}
}
A very simple procedure call demo here.
public class Demo {
private static void prn(int x) {
System.out.println(x);
}
public static void main(String[] args) {
prn(2);
prn(3);
}
}
Got it?
精彩评论