DOC

Java

By Amber Arnold,2014-05-22 10:27
10 views 0
Java

1..Studnts 类,

     《一》

    import javax.swing.JOptionPane;

public class Student1{

     private String Name;

     private String Address;

     private float[] score=new float[3];

     public Student1 (String name,String address,float[] score)

     {

     this.Name=name;

     this.Address=address;

     this.score=score;

     }

     public Student1 (float[] score){

     score[1]=score[2]=score[0]=0;

     }

     public void setTestScore(int num,float[] score)

     {

     this.score[num-1]=score[num-1];

     }

     public float getTestScore(int num)

     {

     return score[num-1];

     }

     public float average(){

     float ave=(score[0]+score[1]+score[2])/3;

     return ave;

     }

     public String toString()

     {

     String result;

     result="The student Name :"+Name+"\n"+"the address "+Address+"

    \n";

     result+="three score are "+score[0]+" "+score[1]+" "+score[2]+"

    \n"+"the average is "+average()+'\n';

     return result;

     }

    }

    class show1{

     public static void main(String[] args) {

     float ave;

     float[] fl=new float[3];

     String str1,str2;

     while(true){

     String tem1=JOptionPane.showInputDialog(" 请输入名字,");

     str1=String.valueOf(tem1);

     String tem2=JOptionPane.showInputDialog(" 请输入地址,");

     str2=String.valueOf(tem2);

     Student1 stu=new Student1(str1,str2,fl);

     for(int i=0;i<3;i++){

     String temp1=JOptionPane.showInputDialog(" 请输入第 "+(i+1)+" 分数成绩");

     fl[i]=Float.parseFloat(temp1);

     stu.setTestScore((i+1),fl);}

     ave=stu.average();

     JOptionPane.showMessageDialog(null, stu);

     String temp=JOptionPane.showInputDialog("是否继续输入(?Y/N");

     if(temp.equals("Y"))continue;

     else if(temp.equals("N"))break;}

     }}

     《二》

import javax.swing.JOptionPane;

public class Student{

     private String Name;

     private String Address;

     int num;

     float ave,score1,score2,score3;

     public Student (String name,String address)

     {

     this.Name=name;

     this.Address=address;

     }

     public Student (String name,String address,float score1,float score2,float score3){

     this(name,address);

     this.score1=score1;

     this.score2=score2;

     this.score3=score3;

     }

     public void setTestScore(int num,float score1,float score2,float score3)

     {

     this.num=num;

     this.score1=score1;

     this.score2=score2;

     this.score3=score3;

     }

     public float getTestScore(int num)

     {

     return (score1+score2+score3);

     }

     public float average(){

     ave=(score1+score2+score3)/3;

     return ave;

     }

     public String toString()

     {

     String result;

     result="The student Name :"+Name+"\n"+"the address "+Address+" \n";

     result+="The student num is :"+num+" \n"+"three score are "+score1+" "+score2+" "+score3+" \n"+"the average is "+ave+'\n';

     return result;

     }

    }

    class show{

     public static void main(String[] args) {

     float ave,f1,f2,f3;

     int m;

     String str1,str2;

     while(true){

     String tem1=JOptionPane.showInputDialog(" 请输入名字,");

     str1=String.valueOf(tem1);

     String tem2=JOptionPane.showInputDialog(" 请输入地址,");

     str2=String.valueOf(tem2);

     Student stu=new Student(str1,str2,0,0,0);

     String temp=JOptionPane.showInputDialog(" 请输入学号,");

     m=Integer.parseInt(temp);

     String temp1=JOptionPane.showInputDialog(" 请输入第1"+"门分数成");

     f1=Float.parseFloat(temp1);

     String temp2=JOptionPane.showInputDialog(" 请输入第2"+"门分数成");

     f2=Float.parseFloat(temp2);

     String temp3=JOptionPane.showInputDialog(" 请输入第3"+"门分数成

");

     f3=Float.parseFloat(temp3);

     stu.setTestScore(m,f1,f2,f3);

     ave=stu.average();

     JOptionPane.showMessageDialog(null, stu);

     temp=JOptionPane.showInputDialog("是否继续输入(?Y/N");

     if(temp.equals("Y"))continue;

     else if(temp.equals("N"))break;}

     }}

    2.Course类,

    import javax.swing.JOptionPane;

public class Course{

     private String[] Name=new String[5];

     private String Address,Course;

     float[] score=new float[5];

     public Course(String Course){

     this.Course=Course;

     }

     public Course(String Course,float[] score){

     this(Course);

     this.score=score;

     }

     public void addStudent(int num,String[] Name){

     this.Name[num-1]=Name[num-1];

     }

     public void setScore(int num,float[] score){

     this.score[num-1]=score[num-1];

     }

     public float average(){

     float ave=(score[0]+score[1]+score[2]+score[3]+score[4])/5;

     return ave;

     }

     public String roll(){

     return ("名字, "+Name[0]+ " "+"分数为, "+score[0]+"\n"+"名字, "+Name[1]+" "+ "分数为, "+score[1]+"\n"+"名字, "

     +Name[2]+" "+ "分数为, "+score[2]+"\n"+"名字, "+Name[3]+" "+ "

    分数为, "

     +score[3]+"\n"+"名字, "+Name[4]+ " "+"分数为, "+score[4] );

     }

     public String toString()

     {

     String result;

     result=" 学生的名单及成绩为, "+"\n"+roll()+"\n";

     result+="该门课程为," + " "+Course +"\n"+"平均成绩为, "+average()+'\n';

     return result;

     }

    }

    class show1{

     public static void main(String[] args) {

     float ave;

     String[] str=new String[5];

     float[] fl=new float[5];

     String str3;

     String tem3=JOptionPane.showInputDialog(" 请输入课程名字,");

     str3=String.valueOf(tem3);

     Course s=new Course(str3,fl);

     for(int i=0;i<5;i++){

     String temp1=JOptionPane.showInputDialog(" 请输入第

    "+(i+1)+" 个学生的名字");

     str[i]=String.valueOf(temp1);

     s.addStudent((i+1),str);}

     for(int i=0;i<5;i++){

     String temp1=JOptionPane.showInputDialog(" 请输入第 "+(i+1)+" 个学生的成绩");

     fl[i]=Float.parseFloat(temp1);

     s.setScore(i+1, fl);}

     ave=s.average();

     JOptionPane.showMessageDialog(null, s);

     }}

    3.抛硬币;

    import javax.swing.JOptionPane;

public class Coin {

     private final int HEADS=0;

     private final int TAILS=1;

     private int face;

     public Coin(){

     flip();

     }

     public int flip(){

     face=(int)(Math.random()*2);

     return face;

     }

     public boolean isHeads(){

     return (face==HEADS);

     }

     public String toString(){

     String facename;

     if(face==HEADS)

     facename="Heads";

     else

     facename="Tails";

     return facename;

     }

    }

    class Monetary extends Coin{

     int FACE;

     public int FaceCoin(){

     FACE=super.flip();

     return FACE;

     }

    }

    class Show{

     public static void main(String[] args) {

     int a,sum=0,count=0;

     int temp1=0;

     Monetary mon=new Monetary();

     Coin coin=new Coin();

     JOptionPane.showMessageDialog(null, "欢迎进入?");

     do{

     a=mon.FaceCoin();

     JOptionPane.showMessageDialog(null," " +(count+1)+" 次掷硬币的面值

    为,"+mon.FACE+"\n"+"即出现的是?Heads/Tails : "+mon.toString());

     sum+=a;

     count++;

     temp1=JOptionPane.showConfirmDialog(null,"是否继续掷硬币?");

    /*if(temp.equals("Y"))

     continue;

     else if(temp.equals("N"))break;*/ }while(temp1==JOptionPane.OK_OPTION);

     JOptionPane.showMessageDialog(null, "你总共掷了 " +count+" 次硬币"

    +"\n"+"所有硬币面值和为, "+sum,"谢谢使用!再见?",JOptionPane.INFORMATION_MESSAGE); }

     }

    4.医院员工系统,

     <>

    import javax.swing.JOptionPane;

     public class Employees {

     private String EmployeeType;

     private Employees() {

     // TODO Auto-generated method stub

     }

     public Employees(String EmployeerType){

     this.EmployeeType=EmployeerType;

     }

     public String toString(){

     String result;

     result="该职员的职务是, "+EmployeeType+"\n";

     return result;

    }

    }

    class Doctor extends Employees{

     public Doctor(String doctor){

     super(doctor);

     }

     public String KanBing(){

     String str;

     str="工作是,主要负责看病和诊断 "+"\n";

     str+="医院医生的月平均工资是,5000 ";

     return str;

     }

     public String toString(){

     String result=super.toString();

     result+=KanBing();

     return result;

     }

    }

    class Nurse extends Employees{

     public Nurse(String Nurse){

     super(Nurse);

     }

     public String ZhaoGu(){

     String str;

    "+"\n"; str="工作是,主要负责给病人打针及照顾病人

     str+="医院护士的月平均工资是, 3000 ";

     return str;

     }

     public String toString(){

     String result=super.toString();

     result+=ZhaoGu();

     return result;

     }

    }

    class manager extends Employees{

     public manager(String manager){

     super(manager);

     }

     public String GuanLi(){

     String str;

     str="工作是,主要负责医院的管理制度和运营?"+"\n";

     str+="医院管理人员的月平均工资是, 4000 ";

     return str;

     }

     public String toString(){

     String result=super.toString();

     result+=GuanLi();

     return result;

     }

    }

    class Chirurgeon extends Employees{

     public Chirurgeon(String Chirurgeon){

     super(Chirurgeon);

     }

     public String ZhiLiao(){

     String str;

     str="工作是,主要负责外科方面的治疗及外科手术?"+"\n";

     str+="医院外科医生的月平均工资是,5000 ";

     return str;

     }

     public String toString(){

     String result=super.toString();

     result+=ZhiLiao();

     return result;

     }

    }

    class Dest_clerk extends Employees{

     public Dest_clerk(String Dest_clerk){

     super(Dest_clerk);

     }

     public String JieDai(){

     String str;

     str="工作是,主要负责接待外来客人及病人家属?"+"\n";

     "; str+="医院接待员的月平均工资是,3000

     return str;

     }

     public String toString(){

     String result=super.toString();

     result+=JieDai();

     return result;

     }

    }

    class Guard extends Employees{

     public Guard(String Guard){

     super(Guard);

     }

     public String AnQuan(){

     String str;

     str="工作是,主要负责医院的安全问题 "+"\n";

     str+="医院门卫的月平均工资是,2500 ";

     return str;

     }

     public String toString(){

     String result=super.toString();

     result+=AnQuan();

     return result;

     }

    }

    class Staff{

     public static void main(String[] args) {

     String[] staff=new String[6];

     staff[0]="Doctor";

     staff[1]="Nurse";

     staff[2]="manager";

     staff[3]="Chirurgeon";

     staff[4]="Dest_clerk";

     staff[5]="Guard";

     int choice;

     JOptionPane.showMessageDialog(null, "欢迎进入医院员工管理系统?");

     while(true){

     String temp=JOptionPane.showInputDialog("请输入你的选择,\n\t1.

    医生\n\t2.护士\n\t3.管理人员\n\t4.外科医生\n\t5.接待员\n\t6.门卫\n\t#.退出");

     try{

     choice=Integer.parseInt(temp);

     switch(choice){

     case 1:

     Doctor doc=new

    Doctor(staff[choice-1]);JOptionPane.showMessageDialog(null, doc);break;

     case 2:

     Nurse nur=new

    Nurse(staff[choice-1]);JOptionPane.showMessageDialog(null, nur);break;

     case 3:

     manager man=new

    manager(staff[choice-1]);JOptionPane.showMessageDialog(null, man);break;

     case 4:

     Chirurgeon chi=new

    Chirurgeon(staff[choice-1]);JOptionPane.showMessageDialog(null, chi);break;

     case 5:

Report this document

For any questions or suggestions please email
cust-service@docsford.com