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

📄 userinterface.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
package Interfaces;

import java.io.*;
import dslib.list.LinkedListUos;
import Entities.*;

/**	A generic interface for users of the registration system. */
public abstract class UserInterface
{
	BufferedReader input = null;
	
	/**	User Input */
	public abstract int getCommandID();

	/**	Read in a double value*/
	public double readInput(String msg)
	{
		input = new BufferedReader(new InputStreamReader(System.in));
		/**	assume the worse from start */
		boolean badChoice = true; 
		double theChoice = -1;	
	
		do
		{
			System.out.print(msg);
			try
			{
				theChoice = Double.parseDouble(input.readLine());
			} catch (Exception e) {}
		
			if (theChoice <= 0)
				System.out.println("Invalid input" + ". Try again! ");
			else
				badChoice = false;
		} while (badChoice);
		return theChoice;
	}

		/**	Read in a string */
	public String readString(String msg)
	{
		input = new BufferedReader(new InputStreamReader(System.in));
		/**	assume the worse from start */
		boolean badChoice = true; 
		String theChoice = "";	
		
		do
		{
			System.out.print(msg);
			try
			{
				theChoice = input.readLine();
			} catch (Exception e) {}
		
			if (theChoice.equals(""))
				System.out.println("Invalid input" + ". Try again! ");
			else
				badChoice = false;
		} while (badChoice);
		return theChoice;
	}

	/**	Display a list of grades */
	public void showGradeList(LinkedListUos list)
	{
		if (list.isEmpty())
			System.out.println("\nNo Grades recorded");
		else
		{
			System.out.println("\nThe current grades recorded are : \n");
			showList(list);
		}
	}

	/**	Display the list */
	protected void showList(LinkedListUos list)
	{
		list.goFirst();
		while (!list.after())
		{
			System.out.print(list.item());
			list.goForth();
		}
		System.out.println();
	}	

	/**	Prompt the user for the section number */
	public int getSectionNumber()
	{
		return (int)readInput("\nEnter the section number : ");
	}

	/**	Prompt the user for the section number */
	public int getDeptNumber()
	{
		return (int)readInput("\nEnter the department number : ");
	}
	
	/**	Prompt the user for the course number */
	public int getCourseNumber()
	{
		return (int)readInput("\nEnter the course number : ");
	}	
	/**	Prompt the user for class numbers */
	public CallNum getCallNum()
	{
		return new CallNum(getDeptNumber(),getCourseNumber(),
					getSectionNumber());
	}
	
	/**	Tell the user that they have made an invalid choice */
	public void showInvalidChoice()
	{
		System.out.println("\n Invalid choice.");
		System.out.println(" Please make another selection.");
	}		
} /* end of UserInterface */

⌨️ 快捷键说明

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