Java学习笔记学生请假系统
{:301_998:}学习java根据事例,写了一个java的请假系统然后分享一下给大家参考一下然后关于ArrayList其实不太明白。
首先先定义一个person类吧。然后后面studentteacher继承
package Test1;
public class Person {
private String id;
private String sf;
private String name;
private int age;
Person(String sf,String id,String name,int age)
{ this.sf=sf;
this.id=id;
this.name=name;
this.age=age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSf() {
return sf;
}
public void setSf(String sf) {
this.sf = sf;
}
}
然后写一个请假方法
package Test1;
public class Qingjia {
private int id;
private String sf;
private String Personid;
private int zhuangtai;
private int numday;
private static int tid;
Qingjia(String sf,String Personid,int numday)
{
tid++;
this.sf=sf;
this.id=tid;
this.Personid=Personid;
this.zhuangtai=0;
this.numday=numday;
}
public int getId() {
return id;
}
public String getSf() {
return sf;
}
public void setSf(String sf) {
this.sf = sf;
}
public void setId(int id) {
this.id = id;
}
public String getPersonid() {
return Personid;
}
public void setPersonid(String personid) {
Personid = personid;
}
public int getZhuangtai() {
return zhuangtai;
}
public void setZhuangtai(int zhuangtai) {
this.zhuangtai = zhuangtai;
}
public int getNumday() {
return numday;
}
public void setNumday(int numday) {
this.numday = numday;
}
}
定义一个学生类继承person类,并且写上请假方法
package Test1;
import java.util.ArrayList;
public class Student extends Person {
Student(String sf, String id, String name, int age) {
super(sf, id, name, age);
// TODO Auto-generated constructor stub
}
public void Qingjia(String sf1,ArrayList<Qingjia> list,int n)
{
Qingjia qj=new Qingjia(sf1,this.getId(),n);
list.add(qj);
}
}
之后写一个老师类继承person类,写上请假审批和请假
用来审批学生请假
package Test1;
import java.util.ArrayList;
import java.util.Scanner;
public class Teacher extends Person{
Teacher(String sf, String id, String name, int age) {
super(sf, id, name, age);
// TODO Auto-generated constructor stub
}
public int PassQingjia(ArrayList<Qingjia> list)
{
int a=0;
System.out.println("请假情况如下:");
for(int i=0;i<list.size();i++)
{
System.out.println(list.get(i).getId()+" "+list.get(i).getSf()+" "+list.get(i).getPersonid()+"请假天数"+list.get(i).getNumday()+"同意状态 "+list.get(i).getZhuangtai());
}
System.out.println("结果");
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<list.size();i++)
{
if (list.get(i).getId()==n)
{
list.get(i).setZhuangtai(1);
}
if (list.get(i).getId()==0)
{
a++;
}
}
for(int i=0;i<list.size();i++)
{
System.out.println(list.get(i).getId()+" "+list.get(i).getSf()+" "+list.get(i).getPersonid()+"请假天数"+list.get(i).getNumday()+"请假状态"+list.get(i).getZhuangtai());
}
return a;
}
public void Qingjia(String sf1,ArrayList<Qingjia> list,int n)
{
Qingjia qj=new Qingjia(sf1,this.getId(),n);
list.add(qj);
}
}
然后写一个领导类继承person 写一个审批请假的方法
package Test1;
import java.util.ArrayList;
import java.util.Scanner;
public class Leader extends Person {
Leader(String sf, String id, String name, int age) {
super(sf, id, name, age);
// TODO Auto-generated constructor stub
}
public int PassQingjia(ArrayList<Qingjia> list)
{
int a=0;
System.out.println("请假情况如下:");
for(int i=0;i<list.size();i++)
{
System.out.println(list.get(i).getId()+" "+list.get(i).getSf()+" "+list.get(i).getPersonid()+"
请假天数"+list.get(i).getNumday()+"同意状态 "+list.get(i).getZhuangtai());
}
System.out.println("结果");
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<list.size();i++)
{
if (list.get(i).getId()==n)
{
list.get(i).setZhuangtai(1);
}
if (list.get(i).getId()==0)
{
a++;
}
}
System.out.println("请假情况如下");
for(int i=0;i<list.size();i++)
{
System.out.println(list.get(i).getId()+"
"+list.get(i).getSf()+" "+list.get(i).getPersonid()+"请假天数"+list.get(i).getNumday()+"请假状态"+list.get(i).getZhuangtai());
}
return a;
}
public void Qingjia(String sf1,ArrayList<Qingjia> list,int n)
{
Qingjia qj=new Qingjia(sf1,this.getId(),n);
list.add(qj);
}
}
最后写一个主函数测试。
package Test1;
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<Qingjia> list=new ArrayList<Qingjia>();
Student s1=new Student("学生","0413170301","JOB", 19);
s1.Qingjia("Student",list, 2);
Student s2=new Student("学生","0413170302","Bob", 19);
s2.Qingjia("Student",list, 2);
System.out.println(list.get(0).getId()+" "+list.get(0).getPersonid()+" "+list.get(0).getZhuangtai()+" "+list.get(0).getNumday());
Teacher t1=new Teacher("老师
","0123456","tot",27);
t1.Qingjia("Teacher",list, 15);
Leader l1=new Leader("领导","0147852","hub",20);
t1.PassQingjia(list);//老师审批学生请假
t1.PassQingjia(list);//同上
l1.PassQingjia(list);//学生审批老师请假
}
}
然后我也是一个新手在学java。分享一下我的学习历程吧。 掌握了这个,推荐学一下 Activiti,然后基于Activiti的理解再转一下flowable或者直接学flowable。 向楼主学习~! 跟着楼主学习 命名最好英文的见名知义,看起来会比较舒服一点,个人意见。拼音看起来不舒服... 同为java学习新手 支持下,学习JAVA的新手 不错哟,学习一下 期待楼主这个小练习早日成型!:lol
页:
[1]
2