java题目,求助大神了
public class Day31 {
public static void main(String[] args) {
Animal ch=new Chicken("喔喔","芦花鸡","虫子","打鸣");
Animal du=new Chicken("嘎嘎","斑嘴鸭","小皮没鱼虾","游泳饥带");
AnimalAction.script(ch);
AnimalAction.script(du);
}
}
//父类
abstract class Animal{
protected String name,type,hobby,skill;;
protected Animal(String name,String type,String hobby,String skill){
this.name=name;
this.type=type;
this.hobby=hobby;
this.skill=skill;
};
protected void nameFun(){
System.out.println("我叫:"+name+"是一只"燃肢纳+type+"!");
}
protected void hobbyFun(){
System.out.println("我喜欢吃:"+hobby+"!");
}
protected void skillFun(){
System.out.println("我会:"+skill+"!");
}
}
//子类1鸡
class Chicken extends Animal{
public Chicken(String name,String type,String hobby,String skill){
super(name,type,hobby,skill);
}
}
//子类2鸭
class Duck extends Animal{
public Duck(String name,String type,String hobby,String skill){
super(name,type,hobby,skill);
}
}
//调用类;
class AnimalAction{
public static void script(Animal an){
an.nameFun();
an.hobbyFun();
an.skillFun();
}
}
有关java编程题目?
按照题目要求源晌编写的圆,圆锥和测试类的Java程序如下
Test.java文件内容如下
class Circle{
private double r;
private String color;
public Circle(double r){
this.r=r;
}
public double area(){
return Math.PI*r*r;
}
public double perimeter(){
return Math.PI*2*r;
}
public double getR(){
return this.r;
}
public void setR(double r){
this.r=r;
}
public String getColor(){
return this.color;
}
public void setColor(String color){
this.color=color;
}
public String toString(){
return "圆的半径为"+r+",颜色为"+color;
}
}
class Cone{
private Circle c;
private double h;
private String color;
public Cone(Circle c,double h){
this.c=c;
this.h=h;
}
public double volume(){
return 1.0/3*c.area()*h;
}
public Circle getCircle(){
return this.c;
}
public void setCircle(Circle c){
this.c=c;
}
public double getH(){
return this.h;
}
public void setH(double h){
this.h=h;
}
public String getColor(){
return this.color;
}
public void setColor(String color){
this.color=color;
}
public String toString(){
return "圆锥的底面积为"燃悔+c.area()+",高为"+h+",颜色为"+color;
}
}
public class Test{
public static void main(String[] args){
Circle circle1=new Circle(2.5);
circle1.setColor("红色");
System.out.println(circle1.toString());
System.out.println("圆的面积为"+circle1.area());
System.out.println("圆的周雹段锋长为"+circle1.perimeter());
Cone circlar1=new Cone(circle1,2.7);
circlar1.setColor("蓝色");
System.out.println(circlar1.toString());
System.out.println("圆锥的体积为"+circlar1.volume());
}
}
java练习题求完整代码
按照题目要求编写的用javaBean规范设计的学生类Student的Java程序如下
需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果
Student.java文件扮租代码如下
package user.java.test;
import java.io.Serializable;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private String no;
private String name;
private double score;
public Student(){}
public Student(String no,String name,double score){
this.no=no;
this.name=name;
this.score=score;
}
public String getNo(){ return no;}
public void setNo(String no){ this.no=no;}
public String getName(){ return name;}
public void setName(String name){ this.name=name;}
public double getScore(){ return score;}
public void setScore(double score){ this.score=score;}
public String toString(){
return "学号:"+no+",姓名:"+name+",成绩:"+score;
}
public static double getAvg(Student[] sArray){
double sum=0,avg;
for(int i=0;isArray.length;i++){
sum=sum+sArray[i].getScore();
}
avg=sum/sArray.length;
return avg;
}
}
Test.java文件代码如下
package user.java.test;
public class Test{
public static void main(String[] args){
Student[] sArray=new Student[5];
sArray[0]=new Student("001","张三",89.5);
sArray[1]=new Student("002","李四",82.5);
sArray[2]=new Student("003","王五",93);
sArray[3]=new Student("004"皮缺和,"赵六",73.5);
sArray[4]=new Student("005","燃盯孙七",66);
System.out.println("这些学生的平均分:"+Student.getAvg(sArray));
for(int i=0;isArray.length;i++){
System.out.println(sArray[i].toString());
}
}
}
java课程设计题目及代码是什么?
java课程设计题目及代码分别是:
1、题目:计算器。设计内容是设计一个图形界面(GUI)的计算器应用程序,完成简单的算术芹此蔽运算。
设计要求是设计的计算器应用程序可以完成家法、减法、乘法、扒旦除法和取余运算。且有小数点、正负号、求倒数、退格和清零功能。
2、代码:
数字按钮NumberButton类如下:
import java.awt.
import java.awt.event.
import javax.swing.
public class NumberButton extends Button.
{
int number.
public NumberButton(int number).
{
super(""+number).
this.number=number.
setForeground(Color.blue).
}
public int getNumber().
{
return number;
}
}
其它java课程设计题目及代码是:
题目:华容道。编写一个按钮的子类,使用该子类创建的对象代表华容道中的人物。通过焦点事件控制人物颜色,当人物获得焦点时颜色为蓝色,当失去焦点时颜色为灰色。
通过键盘事件和鼠标事件来实现曹操、关羽等人物的移动。当人物上发生鼠标事件或键盘事件时,如果鼠标指针的位置是在人物的下方(也就是组件的下半部分)或按下键盘的“↓“键,该人物向下移动。向左、向右和向上的移动原理类似。
代码是:
String name[]={"曹操","关羽","张","刘","嫌州马","许","兵","兵","兵","兵"}.
for(int i=0;iname.length;i++).
{
person[i]=new Person(i,name[i]).
person[i].addKeyListener(this).
person[i].addMouseListener(this).
// person[i].addFocusListener(new Person).
add(person[i]).
}
person[0].setBounds(104,54,100,100).
person[1].setBounds(104,154,100,50).
person[2].setBounds(54,154,50,100).
person[3].setBounds(204,154,50,100).
person[4].setBounds(54,54,50,100).
person[5].setBounds(204,54,50,100);
person[6].setBounds(54,254,50,50);
person[7].setBounds(204,254,50,50);
person[8].setBounds(104,204,50,50);
person[9].setBounds(154,204,50,50);
几道JAVA题目,求好心人给下答案,感激不尽
1、public static void main(String[] args)
2、public finall static
3、3
4、抽象类
5、implements
6、类:一个包含属性、方法,使用class关键字定义
对象:创建对象必须使用new关键字,对象其实在内锋森存中存储的是类的引用地址。
7、try是可能发生异常的内容;
catch是发生异常握宏后要处理的代码;
finally是始终执行的,比如关闭资源等。
8、银皮亩
public class Demo {
//小明今年12岁,他母亲比他大20岁。编程计算多少年后他母亲的年龄是小明的2倍。
public static void main(String[] args) {
System.out.println(getYeah());
}
public static int getYeah(){
int xmAge = 12,mqAge = 20,yeah = 0;
while(true){
if(mqAge / 2 == xmAge){
return yeah;
}
mqAge++;
yeah++;
}
}
}
9、
public class Demo {
public static void main(String[] args) {
new Thread(new Piao()).start();
new Thread(new Piao()).start();
new Thread(new Piao()).start();
new Thread(new Piao()).start();
}
}
class Piao implements Runnable{
private static int piao = 1;
public void run(){
while(true){
synchronized(Piao.class){
if(piao 100){
System.exit(0);
}
System.out.println(Thread.currentThread().getName()+"出票:" + piao + "号");
piao++;
}
}
}
}