定义一个雇员类Employee,包括属性:姓名,工号,年龄,工资。

1、定义一个雇员类Employee,包括属性:姓名,工号,年龄,工资。
要求:工号的构成方式:(入职年月份)-(性别)-(3位随机序列码),其中入职年月份格式为yyyyMMdd;性别(枚举)为男记录00,性别为女记录01;随机号码长3,且不能全0或全1.

提供方法实现:1)从工号提取入职日期(Date),提取性别,提取随机序列码
2)根据输入的入职日期(Date)、性别,生成随机序列码,组成工号。

package java3;

import java.io.*;
import java.util.*;
public class Employee {
	
	public String name;
	public String ID;
	public int age;
	public String salary;
	
	
	public Employee(String name,String ID,int age,String salary){
		
		this.name=name ;
		this.ID=ID;
		this.age=age;
		this.salary=salary;
		
	}
	
	public  String getID() {
		return ID;
	}
	public void setID(String ID) {
		this.ID=ID;
	}
	
	
	
	public void show() throws Exception {
		
		String str=ID;
      String age=str.substring(8,10);	
      String randnum=str.substring(10,13);	
      if(age.equals("00")) {
			System.out.println("性别:男");
		}
      else System.out.println("性别:女");
	
      System.out.println("随机序列码"+randnum);
      /*	int n=-1;

		byte[] b=new byte[20];
		FileInputStream fis =new FileInputStream(str); 
		FileInputStream fis1 =new FileInputStream(str);
	  while((n=fis.read(b,9,2))!=-1) {
			String  age1=String.valueOf(n);
			int a= n;
		
			if(a==00) {
				System.out.println("性别:男");
			}
			System.out.println("性别:女");
			
			System.out.println("性别:"+ age1);
			  
		}
		
		while((n=fis1.read(b,11,3))!=-1) {
			String randnum=String.valueOf(n);
			System.out.println("随机序列码:" +randnum);
		}
		*/

		
	}
	
	
	public static void main(String []args) throws Exception {
		Scanner input =new Scanner(System.in); 
		StringBuffer str0=new StringBuffer();
		String str1=" ";
	    System.out.println("pleaess input rznianfen yyyyMMdd\n");
	    
		str1=input.nextLine();
		str0.append(str1);
		System.out.println("pleaess input sex 00or01\n");
		
	    str1=input.nextLine();
		str0.append(str1);
		System.out.println("pleaess input three bits rand number without all 0 or 1\n");
		
		 str1=input.nextLine();
		str0.append(str1);

		String str2=new String(str0);
		Employee em =new Employee("zengtao",str2,22,"5800");
     
        
        
	
     System.out.println("从工号提取入职日期(Date),提取性别,提取随机序列码");
		em.show();
	System.out.println();
	System.out.println("根据输入的入职日期(Date)、性别,生成随机序列码,组成工号:。");
		
	   String str= em.getID();
       System.out.println(str);
		
	}

}
原创文章 45 获赞 7 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_41814777/article/details/103281208