SSD3-EXAM1

import  java.io.*;
import  java.util.*;

/* DOCUMENT THIS CLASS */
public class StudentApplication  {

    /* Standard input stream */
    private static BufferedReader  stdIn =
        new  BufferedReader(new  InputStreamReader(System.in));

    /* Standard output stream */
    private static PrintWriter  stdOut =
        new  PrintWriter(System.out, true);

    /* Standard error stream */
    private static PrintWriter  stdErr =
        new  PrintWriter(System.err, true);

    /* Delimiter of student values */
    private static final String DELIM = "_";

    /* Minimum grade */
    private static final int MIN_GRADE = 0;

    /* Maximum grade */
    private static final int MAX_GRADE = 100;

    /**
     * This program reads, from the standard input, a student's grades;
     * and then displays, to the standard output, that student's average.
     *
     * @param args  not used
     * @throws IOException  if error reading from the standard input.
     */
    public static void main(String[]  args) throws IOException  {

        Student student = readStudent();

        stdOut.println("The average of the student is: "  +
            student.computeAverage());
    }

    /* DOCUMENT THIS METHOD */
    public static Student readStudent() throws IOException {

        String name = "";
        int exam1 = 0;
        int exam2 = 0;
        int exam3 = 0;


        /* PLACE YOUR CODE HERE */
       
        do{
            try{
                 stdErr.println();
                 stdErr.print("student [name_exam1_exam2_exam3]> ");
                 stdErr.flush();
                 StringTokenizer  tokenizer =
                           new  StringTokenizer(stdIn.readLine(),DELIM);
                
                 if(tokenizer.countTokens()==4){
                    name=tokenizer.nextToken();
                    exam1=Integer.parseInt(tokenizer.nextToken());
                    exam2=Integer.parseInt(tokenizer.nextToken());
                    exam3=Integer.parseInt(tokenizer.nextToken());
                   
                    if(exam1<0||exam1>100||exam2<0||exam2>100||exam3<0||exam3>100){
                         stdErr.println("Number out of range");
                    }else{
                         return new Student(name, exam1, exam2, exam3);
                    }
                       
                 }else{
                    stdErr.println("Invalid input line");
                 }
                  
            }catch(IOException e){
                 stdErr.println("Incorrect number format in the line");
            }

        }while(true);

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值