帮助介绍 Java 过程调用
我有一个 Java 学校项目被分配执行以下操作:
编写一个应用程序以在 大学招生办公室。成为 被这所学校录取的学生 必须有: •一个绩点 平均分 3.0 或更高,并且 入学分数为 60 或更高 • 入学分数为 85 或更高,并且任何 平均绩点 做事 更加用户友好,编写一些代码 对数据进行一些错误检查。
也就是说,如果平均绩点是 不在 0.0 和 4.0 之间或者如果 入学分数不介于 0 和 100,然后打印相应的错误 屏幕上的消息告诉用户 他们输入了无效数据。使用 以上标准来写一个 程序被调用,被接受,需要 平均绩点和入学率 Score 作为参数并返回 no 价值。此过程将打印 “接受”或“拒绝”, 因此。最后写一个主要的 提示用户输入的过程 平均绩点和入学 分数。然后这个程序应该 调用接受的方法来显示 结果。
尽管我在没有彻底阅读说明的情况下愚蠢地编写了下面的代码。我的问题是我不确定如何调用程序。另外,如何将变量传递给这个被调用的过程?任何帮助或其他示例都会有所帮助。下面是我在运行时编写的代码,它不具有被调用的 Accept 过程。
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");
}
}
}
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 accepted 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");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有一个非常简单的过程调用演示。
知道了?
A very simple procedure call demo here.
Got it?