帮忙做一个Java程序设计题

帮忙做一个Java程序设计题,第1张

//接口

public interface Shape{

    public abstract double getPeremeter();

    public abstract double getArea();

}

//矩形类

public class MyRect implements Shape{

    private double width = 0; //宽

    private double height = 0;//长

    private double arc = 0;//对角线

    public MyRect(double width, double height){

        thiswidth = width;

        thisheight = height;

    }

    

    @Override

    public double getPeremeter(){

        return (width + height)  2;

    }

    

    @Override

    public double getArea(){

        return width  height;

    }

    

    public void show(){

        arc = Mathsqrt((width  width) + (height  height))

        Systemoutprintln("长:"+ height + " 宽:" + width + " 面积:" + getArea() + " 对角线:" + arc);

    }

    

}

public class test{

    public static void main(String [] args){

        MyRect myRect = new MyRect(20, 30);

        Systemoutprintln("周长:" + myRectgetPeremeter());

        Systemoutprintln("面积:" + myRectgetArea());

        myRectshow();

    }

}

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();

}

}

}

1 Java源程序编译后会生成一种扩展名为(class)的字节码文件。

2 Java小程序不能单独运行,必须将编译后的文件嵌入到网页中,将其嵌

入时使用的标记是(applet)标记。

3若希望所有的控件在界面上从左至右排列,应采用(FlowLayout)布局,

设置布局调用的方法是(setLayout)。

4若类中定义的成员变量只能被同一个包中的类访问,则该变量的访问修饰符为(protected)。

5 Java通过(接口)实现多重继承。

6 如果有一个类A是B的子类,且能够被不同包中的类所使用,请写出

该类的声明头:(public class A extends B)。

7 InputStream类以(字节)为信息的基本单位。

8 自定义异常类必须是(Exception)类及子类,主动抛出异常的关

键字是(throw)。

9 java中下拉列表框对象的事件处理中,用addItemListener()方法注册监听对象,监听类实现的接口是(ItemListener)。

三、程序填空题

1 下面程序中定义了一个Car类,要求创建一个该类的对象demoCar,该对象调

用set_number方法设置车号属性为3388,调用该对象的show_number方法则

输出车号。将程序补充完整。

class Car

{ int car_number;

void set_number(int car_number)

{ thiscar_number = car_number; }

void show_number()

{ Systemoutprintln(“My car No is :”+car_number); }

}

class CarDemo

{ public static void main(String args[])

{ Car car = new Car();

demoCarset_number(3388);

carshow_number(); }}

2以下是一个applet的完整程序,它使用“宋体”字体,在applet窗口中显

示背景色为黑色,前景色为绿色的字符串“您好!”。

import javaawt;

import javaappletApplet;

public class DrawStringDemo extends Applet {

private Font afont= new Font(“宋体”,FontBOLD,18);

public void init(){

(Colorblack);

}

public void paint(Graphics g){

gsetColor(ColorGREEN);

(afont);

(“您好!”,10,40);

}

}

3程序改错。

①public static void main(String[] args) {

②boolean isValid = false;

③int scores[] = {65,70,69,98,86};

四、分析程序结果题

结果:

a=1

b=1

c=1

a=2

b=2

c=1

a=3

b=1

c=1

a=4

b=2

c=1

应该不会有问题,有问题PM我把。

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

以上就是关于帮忙做一个Java程序设计题全部的内容,包括:帮忙做一个Java程序设计题、JAVA程序设计题!请高手帮我解答!、java程序设计题,帮帮忙给做做看,要一定正确啊,教别人呢,别误人子弟啊,呵呵,谢谢啦等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址:https://54852.com/zz/9344559.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存