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

📄 factorysystem.java

📁 一个简单的职工数据库系统设计
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import sheffield.*;
import java.util.*;
import java.lang.*;
import java.io.*;
//=======================================================================================
//读写文件类
//=====================================================================================
class ReadFile
{
	ArrayList line=null;
	RandomAccessFile fileIn=null;
	String s=null;
  int temp=0;
  String strName=null;
  String strHours=null;
  double hours=0;
  double payperhour=0;
  String strpayperhour=null;
  String strCommission=null;
  String strProductnumber=null;
  double commission=0;
  int productnumber=0;
  double payment=0;
  String strpayment=null;
	//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  public void readFile(String filename)throws NullPointerException,IOException,Exception,
                                             FileNotFoundException,EOFException
  {
  	//---------------------------------------------------------------------------------
  	//函数功能:读文件filename,并把文件中的内容放入line容器中。
  	//参数:filename是将要读写的文件名。
  	//---------------------------------------------------------------------------------
  	   line=new ArrayList();
       try{
           fileIn= new RandomAccessFile(filename,"rw");
           s=fileIn.readLine();
  	       temp=stringToInt(s);              
           while(temp!=0)
           {
           	switch(temp)
           	{
           		case 1: 
           		      strName=fileIn.readLine();
           	        strHours=fileIn.readLine();
           	        hours=stringToDouble(strHours);
           	        strpayperhour=fileIn.readLine();
           	        payperhour=stringToDouble(strpayperhour);
           	        line.add(new WagedEmployee(strName,"wagedEmployee",hours,payperhour));
           	        break;
           	case 2: 
           	       strName=fileIn.readLine();
           	        strHours=fileIn.readLine();
           	        hours=stringToDouble(strHours);
           	        strpayperhour=fileIn.readLine();
           	        payperhour=stringToDouble(strpayperhour);
           	        strProductnumber=fileIn.readLine();
           	        productnumber=stringToInt(strProductnumber);
           	        strCommission=fileIn.readLine();
           	        commission=stringToDouble(strCommission);
           	        line.add(new SalesPerson(strName,"salesperson",
           	                hours,payperhour,productnumber,commission));
           	        break;
           	case 3: 
           	        strName=fileIn.readLine();
           	        strpayment=fileIn.readLine();
           	        payment=stringToDouble(strpayment);
           	        line.add(new Manager(strName,"manager",payment));  
           	        break;         	        
           }
          s=fileIn.readLine();
          temp=stringToInt(s);
          }
           fileIn.close();
      }
      catch(IndexOutOfBoundsException f)
      {
      	f.printStackTrace();
      }
      catch(Exception e)
      {
      	e.printStackTrace();
      }
      finally
      {
      	fileIn.close();
      }       
  }
 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  public int stringToInt(String s)throws IndexOutOfBoundsException
  {
  	//-----------------------------------------------------------------------------
  	//函数功能:将string转换成int。
  	//------------------------------------------------------------------------------
    int number=0;
    int temp=s.length();
    for(int i=0;i<temp;i++)
    {
      char ch=s.charAt(i);
      number=number*10+ch-48;
    }
    return number;
  }
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  public double  stringToDouble(String s)throws IndexOutOfBoundsException
  {
  	//--------------------------------------------------------------------------------
  	//函数功能:将string转换成double。ch==46 其中46为字符'.'。
  	//--------------------------------------------------------------------------------
    double modulus=10;
    double doublevalue=0.0;
    boolean flag=true;
    int size=s.length();
    for(int i=0;i<size;i++)
    {
      char ch=s.charAt(i);
      if(ch==46)
      {
         modulus=0.1;
         flag=false;
         continue;
      }
      if(flag)
      {
         doublevalue=doublevalue*modulus+ch-48;
      }
      else
      {
         doublevalue +=(ch-48)*modulus;
         modulus*=0.1;
     }
     }
     return doublevalue;

  } 
}
//===============================================================================
//启动菜单类。
//=================================================================================
class MenuChoice
{
	  
		private int choiceNumber=0;
		private static boolean  flag=true;
		private sheffield.EasyReader kbd = new sheffield.EasyReader();
		//-------------------------------------------------------------------------------
		//注:这里用static变量和函数,使得读文件只执行一次.
		//##############################################################################
		static ReadFile rFile=null;
		//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&7		
		public static void readfile()
		{
			try{
				if(flag){
			   rFile=new ReadFile();
			   rFile.readFile("hjx.txt");
			  }
			  }
			catch( FileNotFoundException filenotex)
			{
				filenotex.printStackTrace();
			}
			catch( EOFException eofex)
			{
				eofex.printStackTrace();
			}
		  catch(Exception e)
		  {
		  	e.printStackTrace();
		  }
		}	
		//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
		public void choiceMenu()throws Exception
		{
			//-----------------------------------------------------------------------------
			//函数功能:根据用户的选择,而运行相应的功能。0:退出。1:计算员工的工资。2:查找。
			//
			//-------------------------------------------------------------------
				//displayMenu();
				readfile();
				int size=rFile.line.size();
				Employee employee=null;
				switch(choiceNumber)
				{
						case 0:
								System.out.println("Quit");
								break;
						case 1:
						    for(int i=0;i<size;i++)
						    {
						    	employee=(Employee)(rFile.line.get(i));
						    	employee.showPayroll();
						    }						
								break;
						case 2:
						     String strQueryName=kbd.readString();
						     for(int i=0;i<size;i++)
						     {
						     	employee=(Employee)(rFile.line.get(i));
						     	String strName=employee.getName();
						     	if(strQueryName.equals(strName))
						     	{
						     		employee.showPayroll();
						     	}
						     }
								//System.out.println("Search for employee");
								break;
						default :
								System.out.println("你没有按要求选择。请按上面的提示选择!!!");
								break  ;																					
				}
				flag=false;
			}
			//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
				public void setChoiceNumber(int num)
				{
					//-------------------------------------------------------------------------
					//函数功能:设置菜单选择(菜单提示要求),0推出,1计算工资,2查找职工情况.
					//函数参数:int num为0,1,2.
					//------------------------------------------------------------------------
							this.choiceNumber = num ;

⌨️ 快捷键说明

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