大二Java程序设计题,求大神热心解答!

大二Java程序设计题,求大神热心解答!,第1张

/////写着也够累的

public class Cylinder extends Circle{

private double h;

public Cylinder(double h, double r, int x, int y) {

super(r, x, y);

thish = h;

}

public Cylinder(){

}

public double getH() {

return h;

}

public void setH(double h) {

thish = h;

}

public double area(){

return 2 superarea() + superperimeter() h;

}

public double volume() {

return superarea() h;

}

public static void main(String[] args) {

Cylinder cy = new Cylinder(45, 23, 2 , 3);

Systemoutprintln("area: " + cyarea());

Systemoutprintln("volume: " + cyvolume());

}

}

class Circle{

private int x;

private int y;

private double r;

public Circle(){

}

public Circle(double r, int x, int y) {

thisr = r;

thisx = x;

thisy = y;

}

public int getX() {

return x;

}

public void setX(int x) {

thisx = x;

}

public int getY() {

return y;

}

public void setY(int y) {

thisy = y;

}

public double getR() {

return r;

}

public void setR(double r) {

thisr = r;

}

public double perimeter(){

return 2 MathPI r;

}

public double area(){

return MathPI r r;

}

}

完整代码如下:

public class Complex {

private float real; //实部

private float imagin;//虚部

public Complex(){//无参默认为(0, 2)

thisreal = 0F;

thisimagin = 2F;

}

public String toString(){//以a+bi的形式输出的复数

return real + "+" + imagin + "i";

}

// a+ bi + (c+ di) = (a+c) + (b+d)i

public static Complex add(Complex c1, Complex c2){//两个复数相加

Complex complex = new Complex();

complexsetReal(c1getReal() + c2getReal());

complexsetImagin(c1getImagin() + c2getImagin());

return complex;

}

// a+ bi == c + di----> a==c, b==d --> it's true

public static boolean equal(Complex c1, Complex c2){//比较两个复数是否相等

return c1getReal() == c2getReal() && c1getImagin() == c2getImagin();

}

//a + bi + f = (a+f) + bi

public static Complex addFloat(Complex c1, float fValue){//复数加一浮点数

c1setReal(c1getReal() + fValue);

return c1;

}

public float getImagin() {

return imagin;

}

public void setImagin(float imagin) {

thisimagin = imagin;

}

public float getReal() {

return real;

}

public void setReal(float real) {

thisreal = real;

}

}

3, 文件名:Threejava

public class Three {

public static void main(String[] args) {

Student stu = new Student("Zhang San", true, (short)12);

Systemoutprintln("Student name: " + stuname);

Systemoutprintln("Student is a male: " + stusex);

Systemoutprintln("Student's age: " + stuage);

stuwork();

stustudy();

Teacher teacher = new Teacher();

teacherlearnMoney();

}

}

abstract class Person{//抽象类Person

protected String name;

protected boolean sex;

protected short age;

protected abstract void work(); //work抽象方法

}

interface Learnmoney{//Learnmoney接口

public void learnMoney();

}

interface Study{//Study接口

public void study();

}

class Student extends Person implements Study{//Student类

public void work() {

Systemoutprintln("学生的工作是努力学习");

}

public Student(String name, boolean sex, short age){

supername = name;

supersex = sex;

superage = age;

}

public void study() {

Systemoutprintln("学生正在学习");

}

}

class Teacher extends Person implements Learnmoney{

public void work() {

Systemoutprintln("教师的工作是教书育人");;

}

public void learnMoney() {

Systemoutprintln("教师正在赚钱");

}

}

class Docotor extends Person implements Learnmoney{

public void work() {

Systemoutprintln("医生的职责是救死扶伤");

}

public void learnMoney() {

Systemoutprintln("医生正在赚钱");

}

}

------------------------------------

4文件名:Fourjava

public class Four {

public static void main(String[] args) {

Rectangle r = new Rectangle(3, 4);

Systemoutprintln("Area is : " + rarea());

Systemoutprintln("Circle is: " + rcircle());

}

}

class Rectangle{

private double width;

private double height;

public Rectangle(double width, double height){

thiswidth = width;

thisheight = height;

}

public double circle(){//求周长

return (width + height) 2;

}

public double area(){//求面积

return width height;

}

}

--------------------

5Fivejava

public class Five {

public static void main(String[] args) {

AImpl a = new AImpl();

apaint();

}

}

interface A {

public int method1(int x);

public int method2(int x, int y);

}

class AImpl implements A{

public int method1(int x) {

return (int)Mathpow(x, 5);

}

public int method2(int x, int y) {

return x > y x: y;

}

public void paint(){

int result1 = method1(2);

int result2 = method2(2, 8);

Systemoutprintln("method1(2) = " + result1);

Systemoutprintln("method2(2, 8) = " + result2);

}

}

-----------------------------测试

method1(2) = 32

method2(2, 8) = 8

程序写完了

/////////////////////////////////////////////////

public abstract class Person {

public String name;

public int age;

public String sex;

public Person(){

}

public abstract void eat();

/

@return Returns the age

/

public int getAge() {

return age;

}

/

@param age The age to set

/

public void setAge(int age) {

thisage = age;

}

/

@return Returns the name

/

public String getName() {

return name;

}

/

@param name The name to set

/

public void setName(String name) {

thisname = name;

}

/

@return Returns the sex

/

public String getSex() {

return sex;

}

/

@param sex The sex to set

/

public void setSex(String sex) {

thissex = sex;

}

}

/////////////////////////////////////////

/

因为学生也是人,所以要继承人的抽象类

/

public abstract class Student extends Person{

public abstract void study();

}

//////////////////////////////////////

public interface Graduate {

void graduateStudyMethod();

}

/////////////////////////////////////

public class Graduatestudent extends Student implements Graduate{

@Override

public void study() {

Systemoutprintln(getName()+"学生的学习方法");

}

@Override

public void eat() {

Systemoutprintln(getName()+"研究生需要吃饭");

}

public void graduateStudyMethod() {

Systemoutprintln(getName()+"研究生有学习的方法");

}

}

/////////////////////////////////////////

/

因为老师也是人,所以要继承人的抽象类

/

public abstract class Teacher extends Person{

public abstract void work();

}

//////////////////////////////////////////////

/

老师研究生

/

public class TeacherGraduate extends Teacher implements Graduate{

@Override

public void work() {

Systemoutprintln(getName()+"老师需要工作");

}

@Override

public void eat() {

Systemoutprintln(getName()+"老师需要吃饭");

}

public void graduateStudyMethod() {

Systemoutprintln(getName()+"老师研究生的学习方法");

}

}

/////////////////////////////////////

简单的测试类

public class Test {

public static void main(String[] args) {

Graduatestudent student = new Graduatestudent();

studentsetName("wangwenjun");

studentsetAge(24);

studentsetSex("男");

studenteat();

studentgraduateStudyMethod();

studentstudy();

TeacherGraduate teacherGraduate = new TeacherGraduate();

teacherGraduatesetName("liuna");

teacherGraduatesetAge(25);

teacherGraduatesetSex("女");

teacherGraduateeat();

teacherGraduategraduateStudyMethod();

teacherGraduatework();

}

}

/////////////////////////////

最终的输出结果

wangwenjun研究生需要吃饭

wangwenjun研究生有学习的方法

wangwenjun学生的学习方法

liuna老师需要吃饭

liuna老师研究生的学习方法

liuna老师需要工作

public class Point {

int x;

int y;

public Point() {

}

public Point(int x, int y) {

thisx = x;

thisy = y;

}

public Point(int x) {

thisx = x;

thisy = x;

}

public double distance() {//求当前点到原点的距离

return Mathsqrt((x x + y y));

}

public double distance(int x1, int y1) {//求当前点到(x1,y1)的距离

return Mathsqrt((x-x1)(x-x1) + (y-y1) (y-y1));

}

public double distance(Point other){

int x2 = otherx;

int y2 = othery;

return Mathsqrt((x-x2)(x-x2) + (y-y2) (y-y2));

}

}

以上就是关于大二Java程序设计题,求大神热心解答!全部的内容,包括:大二Java程序设计题,求大神热心解答!、JAVA程序设计题!请高手帮我解答!、java求练习题集等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9489844.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存