java程序设计题目(几道JAVA语言程序设计题)

本文目录
- 几道JAVA语言程序设计题
- java课程设计题目及代码是什么
- Java程序设计题目
- java程序设计
- Java程序设计题目 这是我们的作业 每一答题选做一个题目 摆脱哪位大虾能解决我的烦恼
- java程序设计题
- java语言程序设计题
几道JAVA语言程序设计题
1-4:
has-a的关系、contains-a的关系、is-a的关系;
“班级”与“学生”是has-a的关系;
“学生”与“大学生”是is-a的关系。
1-5:
正确,把两个看做是类,“清华大学”包含了“大学”的全部成员,“大学”能接受的信息,“清华大学”一样能接受到。
1-6:
过程:面向对象的分析、面向对象的设计、面向对象的实现;
5个层次:对象-类层、静态属性层、服务层、结构层 、主题层;
引入了:界面管理、任务管理、数据管理。
PS:其实我也是JAVA新手,不知答得对不对,希望这些能对你有帮助,呵呵。。。。
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;i《name.length;i++).
{
person).
person.addKeyListener(this).
person.addMouseListener(this).
// person.addFocusListener(new Person).
add(person).
}
person.setBounds(104,54,100,100).
person.setBounds(104,154,100,50).
person.setBounds(54,154,50,100).
person.setBounds(204,154,50,100).
person.setBounds(54,54,50,100).
person.setBounds(204,54,50,100);
person.setBounds(54,254,50,50);
person.setBounds(204,254,50,50);
person.setBounds(104,204,50,50);
person.setBounds(154,204,50,50);
Java程序设计题目
3, 文件名:Three.java
public class Three {
public static void main(String args) {
Student stu = new Student("Zhang San", true, (short)12);
System.out.println("Student name: " + stu.name);
System.out.println("Student is a male?: " + stu.sex);
System.out.println("Student’s age: " + stu.age);
stu.work();
stu.study();
Teacher teacher = new Teacher();
teacher.learnMoney();
}
}
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() {
System.out.println("学生的工作是努力学习");
}
public Student(String name, boolean sex, short age){
super.name = name;
super.sex = sex;
super.age = age;
}
public void study() {
System.out.println("学生正在学习");
}
}
class Teacher extends Person implements Learnmoney{
public void work() {
System.out.println("教师的工作是教书育人");;
}
public void learnMoney() {
System.out.println("教师正在赚钱");
}
}
class Docotor extends Person implements Learnmoney{
public void work() {
System.out.println("医生的职责是救死扶伤");
}
public void learnMoney() {
System.out.println("医生正在赚钱");
}
}
------------------------------------
4文件名:Four.java
public class Four {
public static void main(String args) {
Rectangle r = new Rectangle(3, 4);
System.out.println("Area is : " + r.area());
System.out.println("Circle is: " + r.circle());
}
}
class Rectangle{
private double width;
private double height;
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public double circle(){//求周长
return (width + height) * 2;
}
public double area(){//求面积
return width * height;
}
}
--------------------
5Five.java
public class Five {
public static void main(String args) {
AImpl a = new AImpl();
a.paint();
}
}
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)Math.pow(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);
System.out.println("method1(2) = " + result1);
System.out.println("method2(2, 8) = " + result2);
}
}
-----------------------------测试
method1(2) = 32
method2(2, 8) = 8
java程序设计
按照题目要求编写的Java程序如下(下面的全部代码需要保存在一个FruitTest.java文件中,
或者两个类分别保存在Fruit.java和FruitTest.java文件中,那样需要加包名,保存在同一个包中)
class Fruit{
private String name;
private String area;
private double price;
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public String getArea(){
return area;
}
public void setArea(String area){
this.area=area;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price=price;
}
}
public class FruitTest{
public static void main(String args){
Fruit apple=new Fruit();
apple.setName("苹果");
apple.setArea("陕西");
apple.setPrice(5.32);
System.out.println("水果名称:"+apple.getName()+",产地:"+apple.getArea()+",单价:"+apple.getPrice()+"元");
Fruit pear=new Fruit();
pear.setName("梨");
pear.setArea("山东");
pear.setPrice(3.57);
System.out.println("水果名称:"+pear.getName()+",产地:"+pear.getArea()+",单价:"+pear.getPrice()+"元");
Fruit pineapple=new Fruit();
pineapple.setName("菠萝");
pineapple.setArea("广西");
pineapple.setPrice(7.65);
System.out.println("水果名称:"+pineapple.getName()+",产地:"+pineapple.getArea()+",单价:"+pineapple.getPrice()+"元");
}
}
Java程序设计题目 这是我们的作业 每一答题选做一个题目 摆脱哪位大虾能解决我的烦恼
第2题:
import java.lang.Math;
import java.util.*;
public class Mianji{
public static void main(String args){
int r=0;
Scanner input=new Scanner(System.in);
System.out.println("请输入一个非负数");
try{
r=input.nextInt();
if(r》0){
double ar=Math.PI*r*r;
double c=2*Math.PI*r;
System.out.println("圆的面积是:"+ar);
System.out.println("圆的周长是:"+c);
}
else
System.out.println("输入的数不是非负数");
}
catch(InputMismatchException In){
System.out.println("你输入的不是整数");
}
}
}
———————————————————————————————————
第3题:
import java.lang.Math;
import java.util.*;
public class Test{
public static void main(String args){
int r=0;
Scanner input=new Scanner(System.in);
System.out.println("请输入一个三位数");
try{
r=input.nextInt();
if(r》=100&&r《1000){
int ar;
ar=r/100;
ar=(r%100)/10;
ar=(r%100)%10;
System.out.println("你输入的三位数是"+r);
System.out.println("反转后的结果是"+ar);
}
else
System.out.println("你输入的不是三位数");
}
catch(InputMismatchException In){
System.out.println("你输入的不是三位数");
}
}
}
———————————————————————————————————
第7题:
import java.lang.Math;
import java.util.*;
public class Mianji{
public static void main(String args){
double x=0,y=0,z=0;
Scanner input=new Scanner(System.in);
System.out.println("请输入三角形的三边长:");
try{
x=input.nextDouble();
y=input.nextDouble();
z=input.nextDouble();
if(x》0 &&z》0&&y》0&&(x+y》z) &&(x+z》y)&&(z+x》y)){
double ar=Math.sqrt((x+y+z)*(x+y-z)*(x+z-y)*(y+z-x))/4;
System.out.println("三角形的面积是:"+ar);
}
else
System.out.println("输入的三边不能构成三角形");
}
catch(InputMismatchException In){
System.out.println("你输入的不是整数");
}
}
}
java程序设计题
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String args) {
BufferedOutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(new File("d:/info.txt")));
String line = "第一行文本\n第二行文本";
out.write(line.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream("d:/info.txt"));
StringBuffer buffer = new StringBuffer();
byte;
while (in.read(buff) != -1) {
buffer.append(new String(buff));
}
System.out.println(buffer);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
in = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
java语言程序设计题
public interface ShapeArea(){
public double area();
}
public class MyRectangle(){
public static double area(double x,double y){
return x*y;
}
public class MyTriangle(){
public static double area(double x,double y,double z){
double s=x+y+z;
returnMath.sqrt(s*(s-x)*(s-y)*(s-z));
}
public class Test(){
public static void mian(String args){
System.out.println(MyRectangle.area(5,10));
System.out.println(MyTriangle.area(3,4,5));
}
}
}

更多文章:
万网DNS名称及用途列表?万网ECS服务器,域名是万网的,域名解析到服务器IP上,为什么别人的域名解析到我的IP上面能打开我的网站
2026年4月19日 21:07
抖音seo加盟哪个平台比较好:抖音seo加盟怎么选一个靠谱的渠道
2026年6月21日 22:45


















