Java测试题
Scenario:Astudentisstudying3subjects.Eachsubjecthas2assessmenttasks.Eachassessmenttas...
Scenario:
A student is studying 3 subjects. Each subject has 2 assessment tasks. Each assessment task is worth 50 marks.
You are to enter the result for each assessment task. Your program will then calculate and print out the total mark and grade for each subject.
The grades are broken down as follows:
Mark Grade
Less than 50 NN
50 – 59 PA
60 – 69 CR
70 – 79 DI
80 – 100 HD
Sample:
Welcome to the student course admin
Collecting information for subject 0
Enter mark out of 50 for Assessment task 0: 45
Enter mark out of 50 for Assessment task 1: 45
Subject Mark: 90 - HD
Collecting information for subject 1
Enter mark out of 50 for Assessment task 0: 15
Enter mark out of 50 for Assessment task 1: 40
Subject Mark: 55 - PA
Collecting information for subject 2
Enter mark out of 50 for Assessment task 0: 33
Enter mark out of 50 for Assessment task 1: 41
Subject Mark: 74 - DI
If the user enters a mark which is invalid / not in the range 0 … 50
The user will be told: “Invalid mark, Re-enter mark!”
Enter mark out of 50 for Assessment task 0: 60
Invalid mark: Re-enter marks!
Enter mark out of 50 for Assessment task 0: 50
要求包含两个类 一个是student 还有一个是class course
会Alice的 可以写一个 Alice program 我会加分的~~~ 展开
A student is studying 3 subjects. Each subject has 2 assessment tasks. Each assessment task is worth 50 marks.
You are to enter the result for each assessment task. Your program will then calculate and print out the total mark and grade for each subject.
The grades are broken down as follows:
Mark Grade
Less than 50 NN
50 – 59 PA
60 – 69 CR
70 – 79 DI
80 – 100 HD
Sample:
Welcome to the student course admin
Collecting information for subject 0
Enter mark out of 50 for Assessment task 0: 45
Enter mark out of 50 for Assessment task 1: 45
Subject Mark: 90 - HD
Collecting information for subject 1
Enter mark out of 50 for Assessment task 0: 15
Enter mark out of 50 for Assessment task 1: 40
Subject Mark: 55 - PA
Collecting information for subject 2
Enter mark out of 50 for Assessment task 0: 33
Enter mark out of 50 for Assessment task 1: 41
Subject Mark: 74 - DI
If the user enters a mark which is invalid / not in the range 0 … 50
The user will be told: “Invalid mark, Re-enter mark!”
Enter mark out of 50 for Assessment task 0: 60
Invalid mark: Re-enter marks!
Enter mark out of 50 for Assessment task 0: 50
要求包含两个类 一个是student 还有一个是class course
会Alice的 可以写一个 Alice program 我会加分的~~~ 展开
3个回答
展开全部
/**
* Student类
* @author hsf
* 没有实质的改动,把有关结果判断的方法放到Course类中,
* 在Student类中new Course的对象调用它的方法,功能是一样的。
*/
public class Student {
public static void main(String[] args) {
System.out.println("Welcome to the student course admin");
Course sc = new Course();
System.out.println("Collecting information for subject 0");
sc.evaluatue();
System.out.println("Collecting information for subject 1");
sc.evaluatue();
System.out.println("Collecting information for subject 2");
sc.evaluatue();
}
}
import java.util.Scanner;
/**
* Course类
*
* @author hsf
*/
public class Course {
int num1, num2;
public void evaluatue() {
Scanner sn = new Scanner(System.in);
Course st = new Course();
System.out.println("Enter mark out of 50 for Assessment task 0:");
num1 = sn.nextInt();
st.check(num1);
System.out.println("Enter mark out of 50 for Assessment task 1:");
num2 = sn.nextInt();
st.check(num2);
int sum = num1 + num2;
if (sum < 100 && sum >= 80) {
System.out.println("Subject Mark:" + sum + "-HD");
} else if (sum >= 70 && sum < 79) {
System.out.println("Subject Mark:" + sum + "-DI");
} else if (sum >= 60 && sum < 69) {
System.out.println("Subject Mark:" + sum + "-CR");
} else if (sum >= 50 && sum < 59) {
System.out.println("Subject Mark:" + sum + "-PA");
} else {
System.out.println("Less than 50 NN");
}
}
public void check(int num) {
boolean flag = true;
while (flag) {
if (num > 50 || num < 0) {
System.out.println("Invalid mark, Re-enter mark!");
Scanner sn = new Scanner(System.in);
if (num == num1) {
System.out
.println("Enter mark out of 50 for Assessment task 0:");
} else {
System.out
.println("Enter mark out of 50 for Assessment task 1:");
}
num = sn.nextInt();
} else {
flag = false;
}
}
}
}
* Student类
* @author hsf
* 没有实质的改动,把有关结果判断的方法放到Course类中,
* 在Student类中new Course的对象调用它的方法,功能是一样的。
*/
public class Student {
public static void main(String[] args) {
System.out.println("Welcome to the student course admin");
Course sc = new Course();
System.out.println("Collecting information for subject 0");
sc.evaluatue();
System.out.println("Collecting information for subject 1");
sc.evaluatue();
System.out.println("Collecting information for subject 2");
sc.evaluatue();
}
}
import java.util.Scanner;
/**
* Course类
*
* @author hsf
*/
public class Course {
int num1, num2;
public void evaluatue() {
Scanner sn = new Scanner(System.in);
Course st = new Course();
System.out.println("Enter mark out of 50 for Assessment task 0:");
num1 = sn.nextInt();
st.check(num1);
System.out.println("Enter mark out of 50 for Assessment task 1:");
num2 = sn.nextInt();
st.check(num2);
int sum = num1 + num2;
if (sum < 100 && sum >= 80) {
System.out.println("Subject Mark:" + sum + "-HD");
} else if (sum >= 70 && sum < 79) {
System.out.println("Subject Mark:" + sum + "-DI");
} else if (sum >= 60 && sum < 69) {
System.out.println("Subject Mark:" + sum + "-CR");
} else if (sum >= 50 && sum < 59) {
System.out.println("Subject Mark:" + sum + "-PA");
} else {
System.out.println("Less than 50 NN");
}
}
public void check(int num) {
boolean flag = true;
while (flag) {
if (num > 50 || num < 0) {
System.out.println("Invalid mark, Re-enter mark!");
Scanner sn = new Scanner(System.in);
if (num == num1) {
System.out
.println("Enter mark out of 50 for Assessment task 0:");
} else {
System.out
.println("Enter mark out of 50 for Assessment task 1:");
}
num = sn.nextInt();
} else {
flag = false;
}
}
}
}
展开全部
import java.util.Scanner;
public class Student
{
int sub0;
int sub1;
int sub2;
public Student()
{
sub0=0;
sub1=0;
sub2=0;
}
public void add(int a,int b)
{
if (a==0) sub0=sub0+b;
if (a==1) sub1=sub1+b;
if (a==2) sub2=sub2+b;
}
public int get(int a)
{
if (a==0) return sub0;
if (a==1) return sub1;
if (a==2) return sub2;
return -1;
}
}
class course
{
public static void main(String[] args)
{
int next=0;
boolean flag=true;
Student s1= new Student();
Scanner read = new Scanner(System.in);
System.out.println("Welcome to the student course admin");
for(int i=0;i<3;i++)
{
System.out.println("Collecting information for subject "+i);
for(int j=0;j<2;j++)
{
System.out.println("Enter mark out of 50 for Assessment task "+j);
while (flag==true)
{
next = read.nextInt();
flag=false;
if ((next<0)||(next>50))
{
System.out.println("Invalid mark, Re-enter mark!");
flag=true;
}
}
s1.add(i,next);
flag=true;
}
String myresult="";
int result=s1.get(i);
if (result<50) myresult=""+result+"-NN";
else if (result<60) myresult=""+result+"-PA";
else if (result<70) myresult=""+result+"-CR";
else if (result<80) myresult=""+result+"-DI";
else if (result<=100) myresult=""+result+"-HD";
System.out.println("Subject Mark "+myresult);
System.out.println();
System.out.println();
System.out.println();
}
}
}
public class Student
{
int sub0;
int sub1;
int sub2;
public Student()
{
sub0=0;
sub1=0;
sub2=0;
}
public void add(int a,int b)
{
if (a==0) sub0=sub0+b;
if (a==1) sub1=sub1+b;
if (a==2) sub2=sub2+b;
}
public int get(int a)
{
if (a==0) return sub0;
if (a==1) return sub1;
if (a==2) return sub2;
return -1;
}
}
class course
{
public static void main(String[] args)
{
int next=0;
boolean flag=true;
Student s1= new Student();
Scanner read = new Scanner(System.in);
System.out.println("Welcome to the student course admin");
for(int i=0;i<3;i++)
{
System.out.println("Collecting information for subject "+i);
for(int j=0;j<2;j++)
{
System.out.println("Enter mark out of 50 for Assessment task "+j);
while (flag==true)
{
next = read.nextInt();
flag=false;
if ((next<0)||(next>50))
{
System.out.println("Invalid mark, Re-enter mark!");
flag=true;
}
}
s1.add(i,next);
flag=true;
}
String myresult="";
int result=s1.get(i);
if (result<50) myresult=""+result+"-NN";
else if (result<60) myresult=""+result+"-PA";
else if (result<70) myresult=""+result+"-CR";
else if (result<80) myresult=""+result+"-DI";
else if (result<=100) myresult=""+result+"-HD";
System.out.println("Subject Mark "+myresult);
System.out.println();
System.out.println();
System.out.println();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询