这是昵称的昵称 发表于 2019-5-10 10:44

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。分享一下我的学习历程吧。

Titanic 发表于 2019-5-10 11:24

掌握了这个,推荐学一下 Activiti,然后基于Activiti的理解再转一下flowable或者直接学flowable。

hssf521 发表于 2019-5-10 10:59

向楼主学习~!

一叶知夏 发表于 2019-5-10 11:01

跟着楼主学习

baichihgl 发表于 2019-5-10 18:02

命名最好英文的见名知义,看起来会比较舒服一点,个人意见。拼音看起来不舒服...

童子tz 发表于 2019-5-13 08:54

同为java学习新手

chenhousi 发表于 2019-5-16 11:49

支持下,学习JAVA的新手

大星King 发表于 2019-6-4 20:16

不错哟,学习一下

轩辕剑syz 发表于 2019-8-3 16:38

Jack.K 发表于 2019-8-4 02:50

期待楼主这个小练习早日成型!:lol
页: [1] 2
查看完整版本: Java学习笔记学生请假系统