Java实验三实验报告 联系客服

发布时间 : 星期一 文章Java实验三实验报告更新完毕开始阅读23daa8eabb68a98270fefa02

}

publicvoid setName(String name) { this.name = name; }

public String getGender() { returngender; }

publicvoid setGender(String gender) { this.gender = gender; }

publicint getAge() { returnage; }

publicvoid setAge(int age) { this.age = age; } }

publicclass Student extends Person { String id; String cname; doublescore;

public Student(String id, String cname, double score) { super();

this.id = id;

this.cname = cname; this.score = score; }

public Student() { //super(); }

public String getId() { returnid; }

publicvoid setId(String id) { this.id = id; }

public String getCname() { returncname; }

publicvoid setCname(String cname) {

3

this.cname = cname; }

publicdouble getScore() { returnscore; }

publicvoid setScore(double score) { this.score = score; }

publicvoid display(){

System.out.println(getName()+\+getGender()+\+getAge()+\+id+\+cname+\+score); } }

publicclass Xiti1 {

publicstaticvoid main(String args[]){

Student s1=new Student(\,\,89.5); s1.setName(\); s1.setGender(\女\); s1.setAge(21); s1.display(); } } 2.

publicclass A { A(){ }

void f(){

System.out.println(\); } }

publicclass B extends A { B(){

4

}

publicvoid g(){ super.f();

System.out.println(\大家好啊!\); } }

publicclass Xiti2 {

publicstaticvoid main(String args[]){ B b=new B(); b.g(); } } 3.

publicclass Pointer { privateintx; privateinty; Pointer(){ }

Pointer(int x,int y){ this.x=x; this.y=y; }

publicint getX() { returnx; }

publicvoid setX(int x) { this.x = x; }

publicint getY() { returny; }

publicvoid setY(int y) { this.y = y; }

void display(Pointer p1,Pointer p2){ System.out.println(\两个点分别是:

\+\+p1.getX()+\+p1.getY()+\+\+p2.getX()+\+p2.getY()+\); }

staticdouble distance(Pointer p1,Pointer p2){ return

5

Math.sqrt(Math.pow((p1.x-p2.x),2)+Math.pow((p1.y-p2.y),2)); } }

publicclass Xiti3 {

publicstaticvoid main(String args[]){ Pointer x1=new Pointer(2,2); Pointer x2=new Pointer(5,6); x1.display(x1,x2);

System.out.println(\这两点的距离是:\+x1.distance(x1,x2)); } } 4.

publicabstractclass Area { abstractdouble area(); }

publicclass RectArea extends Area { doublec; doublek;

RectArea(double c,double k){ this.c=c; this.k=k; }

publicdouble area(){

return (this.c)*(this.k); } }

publicclass RoundArea extends Area{ doubler;

RoundArea(double r){ this.r=r; }

publicdouble area(){

return 3.14*(this.r)*(this.r); } }

import java.util.Scanner;

6