⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentapplication.java

📁 SSD3 icarnegie Exam1
💻 JAVA
字号:
import java.io.*;
import java.util.*;

/**
 * Este programa toma los valores de los 3 tokens que hay dentro de una linea 
 * de entrada y verifica que sean correctos para poderlos promediar.
 * 

 * @version 1.0
 */
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());
	}

	/**
	 * @return los valores de los 3 examenes.
	 * @throws IOException algun error en el formato o el los numeros.
	 */
	public static Student readStudent() throws IOException {

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

		do {
			try {
				stdErr.print("Student [name_exam1_exam2_exam3]> ");
				stdErr.flush();

				String input = stdIn.readLine();

				StringTokenizer tokenizer = new StringTokenizer(input, DELIM);

				int contador = (tokenizer.countTokens());
				name = tokenizer.nextToken();
				exam1 = Integer.parseInt(tokenizer.nextToken());
				exam2 = Integer.parseInt(tokenizer.nextToken());
				exam3 = Integer.parseInt(tokenizer.nextToken());

				if ((contador < 4 || contador > 4)
						|| (exam1 <= MIN_GRADE || exam1 > MAX_GRADE)
						|| (exam2 <= MIN_GRADE || exam2 > MAX_GRADE)
						|| (exam3 <= MIN_GRADE || exam3 > MAX_GRADE)) {
					throw new IOException();
					

				}

				else {		
					
					return new Student(name, exam1, exam2, exam3);

				}

			} catch (NoSuchElementException nse) {
				stdErr.println("Los numeros van separados por _");
			} catch (IOException ioe) {
				stdErr.println("El formato es [name_exam1_exam2_exam3]");
			} catch (NumberFormatException nfe) {
				stdErr.println("Unicamente numeros despues del nombre");
			}
		} while (true);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -