System.out.print(a[i]+"");
}
System.out.println();
System.out.println("去掉值为0的项之后为:
");
for(inti:
b){
System.out.print(i+"");
}
}
}
5.定义10个长度的Student数组,将10个Student对象的年龄全部加1,然后把10个Student对象的详细信息逐行打印出来(数组和ArrayList实现)
实现代码:
第一个类:
publicclassStudent{
publicStringname;
publicStringsex;
publicintage;
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetSex(){
returnsex;
}
publicvoidsetSex(Stringsex){
this.sex=sex;
}
publicintgetAge(){
returnage;
}
publicvoidsetAge(intage){
this.age=age;
}
publicStudent(Stringname,Stringsex,intage){
super();
this.name=name;
this.sex=sex;
this.age=age;
}
}
第二个类:
importjava.util.ArrayList;
importjava.util.List;
publicclassTest001{
staticStudent[]s=newStudent[10];
intk=1;
publicstaticvoidmain(String[]args){
Listli=newArrayList();
for(inti=0;i<10;i++){
li.add(newStudent("zhangsan"+i,"男",20));
}
for(inti=0;i<10;i++){
(li.get(i).age)++;
}
for(inti=0;i<10;i++){
System.out.println(li.get(i).getName()+""+li.get(i).getSex()+""+li.get(i).getAge());
}
}
}
6.有工人,农民,教师,科学家,服务生,其中,工人,农民,服务生只有基本工资.教师除基本工资外,还有课酬(元/天),科学家除基本工资外,还有年终奖,请你写出相关类,将各种类型的员工的全年工资打印出来
实现代码:
(共有7个类)
第一个类:
packagecom.softeem.zy006;
/**
*定义一个人的接口,以供实现
*/
publicinterfacePeople{
publicdoublenum();
}
第二个类:
packagecom.softeem.zy006;
/**
*工人类
*/
publicclassWorkerimplementsPeople{
privatedoublemontherSalary;
publicWorker(doublemontherSalary){
super();
this.montherSalary=montherSalary;
}
publicdoublenum(){
returngetMontherSalary()*12;
}
publicdoublegetMontherSalary(){
returnmontherSalary;
}
publicvoidsetMontherSalary(doublemontherSalary){
this.montherSalary=montherSalary;
}
}
第三个类:
packagecom.softeem.zy006;
/**
*农民类
*/
publicclassPeasantimplementsPeople{
privatedoublemontherSalary;
publicPeasant(doublemontherSalary){
super();
this.montherSalary=montherSalary;
}
publicdoublegetMontherSalary(){
returnmontherSalary;
}
publicvoidsetMontherSalary(doublemontherSalary){
this.montherSalary=montherSalary;
}
publicdoublenum(){
returngetMontherSalary()*12;
}
}
第四个类:
packagecom.softeem.zy006;
/**
*教师类
*/
publicclassTeacherimplementsPeople{
privatedoublemontherSalary;
privatedoubledaySalary;
publicTeacher(doublemontherSalary,doubledaySalary){
super();
this.montherSalary=montherSalary;
this.daySalary=daySalary;
}
publicdoublenum(){
returngetMontherSalary()*12+getDaySalary()*365;
}
publicdoublegetMontherSalary(){
returnmontherSalary;
}
publicvoidsetMontherSalary(doublemontherSalary){
this.montherSalary=montherSalary;
}
publicdoublegetDaySalary(){
returndaySalary;
}
publicvoidsetDaySalary(doubledaySalary){
this.daySalary=daySalary;
}
}
第五个类:
packagecom.softeem.zy006;
/**
*科学家类
*/
publicclassScientistimplementsPeople{
privatedoublemontherSalary;
privatedoubleprojectSalary;
publicScientist(doublemontherSalary,doubleprojectSalary){
super();
this.montherSalary=montherSalary;
this.projectSalary=projectSalary;
}
publicdoublenum(){
returngetMontherSalary()*12+getProjectSalary();
}
publicdoublegetMontherSalary(){
returnmontherSalary;
}
publicvoidsetMontherSalary(doublemontherSalary){
this.montherSalary=montherSalary;
}
publicdoublegetProjectSalary(){
returnprojectSalary;
}
publicvoidsetProjectSalary(doubleprojectSalary){
this.projectSalary=projectSalary;
}
}
第六个类:
packagecom.softeem.zy006;
/**
*服务员类
*/
publicclassWaiterimplementsPeople{
privatedoublemontherSalary;
publicWaiter(doublemontherSalary){
super();
this.montherSalary=montherSalary;
}
publicdoublenum(){
returngetMontherSalary()*12;
}
publicdoublegetMontherSalary(){
returnmontherSalary;
}
publicvoid