0.music
package disici;
import java.util.*;
class instrument{
private static String a;
public instrument(String s) {
}
public void play()
{
System.out.println("弹奏乐器");
}
}
class brass extends instrument{
public brass(String s) {
super(s);
}
public void play()
{
System.out.println("弹奏乐器");
}
public void play2() {
System.out.println("弹奏bress!");
}
}
class wind extends instrument {
public wind(String s) {
super(s);
}
public void play()
{
System.out.println("弹奏乐器");
}
public void play2() {
System.out.println("弹奏wind!");
}
}
public class music {
public static void tune(instrument i) {
i.play();
} public static void main(String[]args) {
Scanner ex=new Scanner(System.in);
int n=ex.nextInt();
music a=new music();
wind b=new wind(null);
brass c=new brass(null);
instrument s=new instrument(null);
a.tune(s);
a.tune(b);
a.tune(c);
}
}
1.mokey
package disici;
import java.util.*;
class mokey{
private static String a;
String s;
public mokey(String s) {
this.s=s;
}
public void speak()
{
System.out.println("咿咿呀呀");
}
}
class people extends mokey{
public people(String s) {
super(s);
}
public void speak()
{
System.out.println("小样的,不错嘛!会说话了!");
}
public void think() {
System.out.println("别说话!认真思考!");
}
}
public class s {
public static void main(String[] args) {
String s;
Scanner ex=new Scanner(System.in);
s=ex.nextLine();
mokey e1=new mokey(s);
people e2=new people(s);
e1.speak();
e2.speak();
e2.think();
}
}
2.矩形
package disici;
import java.util.*;
class juxing
{
private String a;
private String b;
public juxing(String a) {
this.a=a;
this.b=b;
}
public void seta() {
this.a=a;
}
public int geta(int a) {
return a;
}
public void setb() {
this.b=b;
}
public int getb(int b) {
return b;
}
public int s(int a,int b) {
return a*b;
}
}
class changfangti{
private String a;
private String b;
private String c;
public void seta() {
this.a=a;
}
public int geta(int a) {
return a;
}
public void setb() {
this.b=b;
}
public int getb(int b) {
return b;
}
public void setc() {
this.c=c;
}
public int getc(int c) {
return c;
}
public static int v(int a,int b,int c) {
return a*b*c;
}
}
public class ee {
public static void main(String[]args) {
Scanner ex=new Scanner(System.in);
System.out.println("请输入长:");
int a=ex.nextInt();
ex.nextLine();
System.out.println("请输入宽:");
int b=ex.nextInt();
ex.nextLine();
System.out.println("请输入高:");
int c=ex.nextInt();
ex.nextLine();
juxing e1=new juxing(null);
changfangti e2=new changfangti();
e1.geta(a);
e1.geta(b);
e2.geta(a);
e2.getb(b);
e2.getc(c);
System.out.println("底面积:"+e1.s(a,b)+"体积:"+e2.v(a, b,c));
}
}
3.汽车
package disici;
import java.util.*;
class vehicle{
private String wheels;
private String weight;
public void setwheels() {
this.wheels=wheels;
}
public int getwheels(int wheels) {
return wheels;
}
public void setweight() {
this.weight=weight;
}
public int getweight(int weight) {
return weight;
}
public void measge(int wheels,int weight) {
System.out.println("轮胎数:"+wheels+"重量:"+weight);
}
}
class car extends vehicle {
private String loader;
public void setloader() {
this.loader=loader;
}
public int getloader(int loader) {
return loader;
}
public void measge(int loader) {
System.out.println("载人数:"+loader);
}
}
class Truck extends car{
private String payload;
public void setpayload() {
this.payload=payload;
}
public int getpayload(int payload) {
return payload;
}
public void measge(int payload) {
System.out.println("载重量:"+payload);
}
}
public class qiche {
public static void main(String[]args) {
Scanner ex=new Scanner(System.in);
System.out.println("请输入轮胎数:");
int wheels=ex.nextInt();
ex.hasNextLine();
System.out.println("请输入重量:");
int weight=ex.nextInt();
ex.hasNextLine();
System.out.println("请输入载人数:");
int loader=ex.nextInt();
ex.hasNextLine();
System.out.println("请输入载重:");
int payload=ex.nextInt();
ex.hasNextLine();
vehicle e1=new vehicle();
car e2=new car();
Truck e3=new Truck();
e1.getwheels(wheels);
e1.getweight(weight);
e2.getloader(loader);
e3.getpayload(payload);
e1.measge(wheels,weight);
e2.measge(loader);
e3.measge(payload);
}
}