JAVA程序设计题2

JAVA程序设计题2,第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;

}

}

shape接口

圆类

矩形类

角形类1

三角形类2

测试类

下午没事,无聊到想写写代码,但是你这个需求不完整

编译、运行环境为哪个版本的JDK?JDK14?or 5?or 6? or 7?

另外你这个问题需求说的比较模糊,果然是学校风格的需求。。。

问题1中:“各矩阵分别采用静态初始化赋值,动态赋值”是什么意思?

问题2中:"数据转换处理: 季节转换 ,数值加总,比较大小"这一段不明白是啥意思,数据转换规则是什么?数字加总后直接显示?比较各个整数大小后如何输出?

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

这个可以用递归来实现。。。。。代码如下。。。还是想了很久弄出来的。。。。已经测试了的。。。希望能帮到你。。。

import

javautilScanner;

public

class

Test

{

public

static

void

huafenD(int

oldData,int

j,

int

n,StringBuffer

result){

StringBuffer

r

=

new

StringBuffer(result);

for(

int

i

=

j;i<=n;i++){

if(i==n&&i!=oldData)

{

resultappend(i);

Systemoutprintln(resulttoString());

result

=

new

StringBuffer(r);

}

else

if(i!=oldData){

resultappend(i);

resultappend("+");

huafenD(oldData,i,n-i,result);

result

=

new

StringBuffer(r);

}

}

}

public

static

void

main(String

args[])

{

Scanner

in

=

new

Scanner(Systemin);

Systemoutprintln("请输入一个整数(1-10)");

int

data

=

innextInt();

while(data<1||data>10){

Systemoutprintln("您的输入

不符合要求,请重新输入");

data

=

innextInt();

}

if(data==1)Systemoutprintln("无需划分");

else

{

StringBuffer

sb

=

new

StringBuffer();

huafenD(data,1,data,sb);

}

}

}

运行结果示例:

请输入一个整数(1-10)

6

1+1+1+1+1+1

1+1+1+1+2

1+1+1+3

1+1+2+2

1+1+4

1+2+3

1+5

2+2+2

2+4

3+3

1、package nettest;

public class TestArray

{

int a[]={12,34,5,7,9,10};

public int max()

{

int j = a[1];

for(int i :a)

{

if(i > j)

{

j = i ;

}

}

return j;

}

public long avrage()

{

long j = 0l;

for(int i :a)

{

j = j + i;

}

return j/alength;

}

}

2、package nettest;

public class Person

{

String name;

int age;

Person(String name,int age)

{

thisname = name;

thisage = age;

}

public void printInfo()

{

Systemoutprintln("name = "+thisname+" age = "+thisage);

}

}

package nettest;

public class Student extends Person

{

String studentId;

Student(String name, int age)

{

super(name, age);

}

Student(String name, int age,String studentId)

{

super(name, age);

thisstudentId = studentId;

}

public void printInfo()

{

Systemoutprintln("name = "+thisname+" age = "+thisage+" StudentId =" + thisstudentId);

}

}

3、package nettest;

public class TestPrint

{

public static void main(String[] args)

{

for (int i = 1; i<10;i++)

{

for(int j = 0; j<i;j++)

{

Systemoutprint("");

}

Systemoutprintln();

}

}

}

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存