java简答题(2)

2018-11-22 18:26

this.cname=cname;}

public void setDiscount(double discount){ this.discount=discount; }

public void Xprice(){ double Sprice;

System.out.println(\车名=\

System.out.println(\这部车现在打折期间\ Sprice=price*discount;

System.out.println(\这部车打折后的价格是\ } }

public class TestCar {

public static void main(String[] args) throws IOException {

Car car =new Car(\奥迪\ car .Xprice(); } }

9 写出一个point(点)类,该类具有x,y(表示点的横纵坐标)两个属性,定义一个构造方法,以坐标为参数,设置x,y为给定坐标值,定义一个show方法输出该点的坐标值。

public class Point {

private double x; private double y;

public Point(double x,double y) { this.x=x; this.y=y; }

public void show(){

System.out.println(\} }

public class TestPoint() {

public static void main(String[] args){ Point point=new Point(4,6);

System.out.println(point.show());}}

10设计一个学生类,其中成员变量有:学号,姓名,性别,班级,并提供方法打印学生信息,和计算已经创建学生对象的数目。编写一个程序测试这个类。

class Test

{ String name; String sno;

String sclass; char sex;

public Test( String name, String sno, String sclass, char sex){ this.name=name; this.sno=sno;

this.sclass=sclass; this.sex=sex; }

public String getName(){ return this.name;}

public void setSno(String sno){ this.sno=sno;}

public void setScore(String sclass){ this.sclass=sclass;}

public void setScore(char sex){ this.sex=sex;}

public void PrintStudent() {

System.out.println(\姓名:\ 学号: \ 班级:\性别: \ } }

public class TestTest3 {

public static void main(String[] args) {

Test aStu=new Test(\张扬\软件1班\男'); aStu.PrintStudent(); } }

11 设计一个关于三角形的类Trival,其中的属性包括三角形的底di,三角形的高gao,方法包括为di和gao指定初值的构造方法,获取三角形的面积find Area().

public class Trival {

protected float di,gao; public Trival(){ di=0; gao=0; }

public Trival(float di,float gao)

{

this.di=di; this.gao=gao; }

public float findArea(){

return (this.di*this.gao)/2; }

public static void main(String[] args) { Trival t1=new Trival(3.5f,6.6f);

System.out.println(\三角形的面积为:\} }

12 编写一类,描述桌子,包括属性:长、宽、高、颜色。并且使盖类具有功能:在定制桌子(及创建对象时),就可以同时指定桌子的长宽高来定制。也可以同时指定桌子的长宽高颜色来定制。也可以单独指定颜色定制。并编写一个测试类测试这几种方法。

class Test44 { double length; double width; double height; String color;

Test44(double l,double w,double h) { length=l;width=w;height=h;}

Test44(double l,double w,double h,String c) { length=l;width=w;height=h;color=c;} Test44(String c) { color=c;} }

public class Test4{

public static void main(String[] args){ Test44 d1=new Test44(2,1.5,0.6);

System.out.println(\第一个桌子的长,宽,高分别为:\\

Test44 d2=new Test44(2,1.5,0.6,\ System.out.println(\第二个桌子的长,宽,高,颜色分别为:\\ Test44 d3=new Test44(\

System.out.println(\第三个桌子颜色为:\色\ } }

13、输出一个九九乘法表 public class TestNum{

public static void main(String[] args) {

int i,j,n=9;

System.out.print (\ for(i=1;i<=n;i++)

System.out.print (\

System.out.print (\for(i=1;i<=n;i++)

System.out.print (\System.out.println(); for(i=1;i<=n;i++)

{ System.out.print(\

for(j=1;j<=i;j++)

System.out.print(\System.out.println(); }}}

14 电力公司的电费计算标准如下:200度以下,0.65元/度;200~500度,1元/度;超过500度,1.5元/度;编写程序实现输入一用电度数,计算电费并输出电费值。

import java.io.*; public class Test5 {

public static void main(String[] args) throws IOException {

double power; double pay;

InputStreamReader in=new InputStreamReader(System.in); BufferedReader bin=new BufferedReader(in); System.out.println(\请输入用电度数\ power=Integer.parseInt(bin.readLine()); if(power<200)

pay=power*0.65; else if(power<500) pay=power*1; else

pay=power*1.5;

System.out.println(\电费为:\} }

15、编程实现通过相应鼠标事件来实现拖动鼠标简单的画画功能 import java.awt.* import java.applet.* import java.awt.event.*

public class m2 extends Applet implements MouseMotionListener{ int x=0,y=0;

public void init(){

setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); setBackground(Color.green); add MouseMotionListener(this); }

public void paint(Graphics g) {

if(x!=0&&y!=0)

g.setColor(Color.red); g.drawLine(x,y ,x,y); } }

public void Dragged(MouseEvent e){

X=(int)e.getX(); y=(int)e.getY(); repaint(); }

public void mouseMoved(MouseEvent e){ public void update(Graphics g){ paint(g);} }


java简答题(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:Protel DXP元件库快速搜索

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: