我有以下一个java文件内容:
package javatest1;
import java.util.ArrayList;
import java.util.List;
public class javatest1 extends common{
/**
* @param args
*/
public static void main(String[] args) {
person s1=new student("lili",13,"china",88);
person s2=new student("wuwu",12,"china",85);
person s3=new student("zzww",15,"english",78);
person s4=new student("xiaoxiao",16,"china",66);
person s5=new student("xiaoli",11,"china",95);
person t1=new teacher("bigbig",35,"english",5000);
person t2=new teacher("biga",33,"china",3000);
person t3=new teacher("bigb",36,"china",5500);
person t4=new teacher("bigc",31,"china",7500);
person t5=new teacher("bigd",37,"china",6000);
useperson(s1);
useperson(s2);
useperson(s3);
useperson(s4);
useperson(s5);
printseparator();
useperson(t1);
useperson(t2);
useperson(t3);
useperson(t4);
useperson(t5);
}
}
以下是person类中的内容:
package javatest1;
public class person extends common {
private String name;
private int age;
private String country;
public int num=10;
public person()
{
print("This is person.");
}
public person(String name,int age)
{
this.name=name;
if(age>0 && age<100)
{
this.age=age;
}
else
{
this.age=0;
}
}
public person(String name,int age,String country)
{
this.name=name;
if(age>0 && age<100)
{
this.age=age;
}
else
{
this.age=0;
}
this.country = country;
}
public String basicinfo()
{
return "my name is "+this.name+",my age is "+this.age+",my country is "+this.country;
}
public String show()
{
return "my is perpon.";
}
}
以下是student类的内容:
package javatest1;
public class student extends person{
public int num=20;
private int sex;
public student()
{
}
public student(String name,int age,int sex)
{
super(name,age);
this.sex=sex;
}
public student(String name,int age,String country,int sex)
{
super(name,age,country);
this.sex=sex;
}
public String show()
{
return super.basicinfo()+",my is a student,my sex is "+this.sex;
}
}
以下是teacher类内容:
package javatest1;
public class teacher extends person {
private int pay;
teacher()
{
}
teacher(String name,int age,int pay)
{
super(name,age);
this.pay=pay;
}
teacher(String name,int age,String county,int pay)
{
super(name,age,county);
this.pay=pay;
}
public String show()
{
return super.basicinfo()+",my is a teacher,my pay is "+this.pay;
}
}
以下是common类内容:
package javatest1;
import java.util.ArrayList;
import java.util.List;
class swapobj<E>
{
E swapvalue;
}
public class common {
//简单打印
public static <E> void print(E value)
{
System.out.println(value);
}
//字符串每个字符变成ascii码
public static StringBuilder stringchangeasc(String value)
{
char[] ca;
int cai;
StringBuilder sb=new StringBuilder();
ca = value.toCharArray(); //把传过来的value转换为字符数组
for(int i=0;i<ca.length;++i)
{
cai=ca[i];
//print(ca[i]+"的ascii码是"+cai);
sb.append(ca[i]+"的ascii码是"+cai);
sb.append("\n");
}
return sb;
}
//如果输出内容是不同部分的话,用************************************隔开
public static void printseparator()
{
print("************************************");
}
//字符串中每一个字符串大写变小写,小写变大与,如果不是字母的话不改变
public static StringBuilder stringchangcw(String value)
{
int cai = 0;
char[] ca;
List cb=new ArrayList();
StringBuilder sb=new StringBuilder();
ca = value.toCharArray();
for(int i=0;i<ca.length;++i)
{
if(ca[i]>65 && ca[i]<90)
{
cai=ca[i]+32;
}
else
if(ca[i]>97 && ca[i]<122)
{
cai=ca[i]-32;
}
else
{
cai=ca[i];
}
//cai=ca[i]+32;
cb.add(cai);
}
for(int j=0;j<cb.size();++j)
{
int obji=(int) cb.get(j);
char oi=(char)obji;
sb.append(oi);
}
return sb;
}
//对传过来的值相加,得到传过来的值的和,传过来的参数个数不限,喜欢多少个参数都可以
public static int argadd(int... arg){
int sum = 0,len=arg.length;
for(int i=0;i<len;++i){
sum=sum+arg[i];
}
return sum;
}
//对传过来的值找出最大值,传过来的参数个数不限,喜欢多少个参数都可以
public static int argmax(int... arg){
int max = arg[0],len=arg.length;
for(int i=1;i<len;++i){
if(max<arg[i])
{
max=arg[i];
}
}
return max;
}
/*public static <E> E argmax(E... arg){
E max = arg[0];
int len=arg.length;
for(int i=1;i<len;++i){
if(max<arg[i])
{
max=arg[i];
}
}
return max;
}*/
//对传过来的值找出最小值,传过来的参数个数不限,喜欢多少个参数都可以
public static int argmin(int... arg){
int min = arg[0],len=arg.length;
for(int i=1;i<len;++i){
if(min>arg[i])
{
min=arg[i];
}
}
return min;
}
//对传过来的值进行由小到大排序,传过来的参数个数不限,喜欢多少个参数都可以
public static int[] argascsort(int... arg){
int index,temp,len=arg.length;
//print(len);
// print(min);
for(int i=0;i<len-1;++i){
index=i;
for(int j=i+1;j<len;++j)
{
if(arg[index]>arg[j])
{
index=j;
}
}
temp=arg[i];
arg[i]=arg[index];
arg[index]=temp;
}
return arg;
}
//对传过来的值进行由大到小排序,传过来的参数个数不限,喜欢多少个参数都可以
public static int[] argdescsort(int... arg){
swapobj so1=new swapobj();
swapobj so2=new swapobj();
int index,temp,len=arg.length;
for(int i=0;i<len-1;++i){
index=i;
for(int j=i+1;j<len;++j)
{
if(arg[index]<arg[j])
{
index=j;
}
}
temp=arg[i];
arg[i]=arg[index];
arg[index]=temp;
//so1.swapvalue=arg[i];
// so2.swapvalue=arg[index];
// sortdata(so1,so2);
}
return arg;
}
//交换传过来的value1和value2的值
public static void swapdata(swapobj value1,swapobj value2)
{
swapobj temp = new swapobj();
temp.swapvalue=value1.swapvalue;
value1.swapvalue=value2.swapvalue;
value2.swapvalue=temp.swapvalue;
}
/*//(按照格式:[数组中的值])返回数组的格式的字符串
public static StringBuilder printarray(int[] arr)
{
StringBuilder sb = new StringBuilder();
int len=arr.length;
sb.append("[");
for(int i=0;i<len;++i)
{
if(i!=len-1)
{
//System.out.print(arr[i]+",");
sb.append(arr[i]+",");
}
else
{
// (arr[i]+"]");
sb.append(arr[i]+"]");
}
// i!=(len-1)?System.out.print(arr[i]+","):print(arr[i]+"]");
}
return sb;
}
//对数组的顺序倒过来(即第一个元素变成最后一个元素,第二个元素变成倒数第二个元素。。。)
public static void swaparray(int[] arr)
{
int len=arr.length,temp;
for(int start=0,end=len-1;start<end;++start,--end)
{
temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
}
}
//查找find在数组第几个位置
public static int findarray(int[] arr,int find)
{
int len=arr.length,index=-1;
for(int i=0;i<len;++i)
{
if(arr[i]==find)
{
index=i+1;
break;
}
}
return index;
}*/
static class myarray
{
//(按照格式:[数组中的值])返回数组的格式的字符串
public static StringBuilder printarray(int[] arr)
{
StringBuilder sb = new StringBuilder();
int len=arr.length;
sb.append("[");
for(int i=0;i<len;++i)
{
if(i!=len-1)
{
//System.out.print(arr[i]+",");
sb.append(arr[i]+",");
}
else
{
// (arr[i]+"]");
sb.append(arr[i]+"]");
}
// i!=(len-1)?System.out.print(arr[i]+","):print(arr[i]+"]");
}
return sb;
}
/* public static void swaparray(int[] arr)
{
int len=arr.length,temp;
for(int i=0;i<len/2;++i)
{
temp=arr[i];
arr[i]=arr[(len-1)-i];
arr[(len-1)-i]=temp;
}
}*/
//对数组的顺序倒过来(即第一个元素变成最后一个元素,第二个元素变成倒数第二个元素。。。)
public static void swaparray(int[] arr)
{
int len=arr.length,temp;
for(int start=0,end=len-1;start<end;++start,--end)
{
temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
}
}
/* public static <E> void printarray(E[] arr)
{
int len=arr.length;
for(int i=0;i<len;++i)
{
print(arr[i]);
}
}*/
//查找find在数组第几个位置
public static int findarray(int[] arr,int find)
{
int len=arr.length,index=-1;
for(int i=0;i<len;++i)
{
if(arr[i]==find)
{
index=i+1;
break;
}
}
return index;
}
}
/*public static void usestudent(student s)
{
print(s.show());
}
public static void useteacher(teacher t)
{
print(t.show());
}*/
//使用人类显示信息
public static void useperson(person p)
{
print(p.show());
}
}
以上的程序我想的是person类中的show方法我定义成为其中一个方法,但我实际想法并不是把show方法定义为person中的一个方法,而是student和teacher这两个子类特有的方法,但我把person类中的show方法删除掉程序去出问题,各位高手有什么办法修改这个程序,把person类中的show方法删除掉程序也不出问题!
|
|