大二java课程设计题目和代码,大二java课程设计题目和代码和报告

http://www.itjxue.com  2023-01-20 11:54  来源:未知  点击次数: 

求助大神如何用Java写出这两个题目的代码?

第一题

package baidu;

public class Student {

protected String name;

protected int age;

public Student(String name, int age) {

this.name = name;

this.age = age;

}

public void show(){

System.out.println("name = " + name);

System.out.println("age = " + age);

}

}

---------------------------------

package baidu;

public class Undergraduate extends Student {

private String degree;

public Undergraduate(String name, int age, String degree) {

super(name, age);

this.degree = degree;

}

public void show(){

System.out.println("name = " + name);

System.out.println("age = " + age);

System.out.println("degree = " + degree);

}

}

------------------------

package baidu;

public class TestRun {

public static void main(String[] args) {

Student s = new Student("singi",12);

s.show();

Undergraduate ug = new Undergraduate("lily",23,"本科");

ug.show();

}

}

输出:

name = singi

age = 12

name = lily

age = 23

degree = 本科

第二题:

package baidu;

public class Man {

String name;

public Man(String name) {

this.name = name;

}

public void business(){

System.out.println("在方法内输出谈生意");

}

}

----------------

package baidu;

public class SuperMan extends Man {

String name;

public SuperMan(String name, String name1) {

super(name);

this.name = name1;

}

@Override

public void business() {

System.out.println("在方法内输出谈几个亿的大单子");

}

public void fly(){

System.out.println("在方法内输出超人不会飞");

}

}

------------------

package baidu;

public class TestMan {

public static void main(String[] args) {

Man m = new Man("singi");

System.out.println(m.name);

m.business();

SuperMan sm = new SuperMan("lily","xiaoming");

System.out.println(sm.name);

sm.business();

sm.fly();

}

}

输出:

singi

在方法内输出谈生意

xiaoming

在方法内输出谈几个亿的大单子

在方法内输出超人不会飞

一题大二java编程题目,求帮助,有图

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.JTextField;

public class NewFrame {

private JFrame frame;

private JTextArea jt;

private JTextField jname;

private JTextField jnum;

private JTextField jshow;

private JLabel lname;

private JLabel lnum;

private JButton show;

private JButton quit;

public NewFrame(){

frame=new JFrame("添加组件的窗口");

jt=new JTextArea(10,20);

jname=new JTextField(10);

jnum=new JTextField(10);

jshow=new JTextField(9);

lname=new JLabel("用户名:");

lnum=new JLabel("电话:");

show=new JButton("显示");

quit=new JButton("退出");

init();

showMe();

addEventHandler();

}

private void addEventHandler() {

show.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

jt.setText("用户名:"+jname.getText()+"\n"+"电话:"+jnum.getText());

jshow.setText("你按下了显示按钮!");

}

});

quit.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

}

public void init(){

frame.setLayout(new BorderLayout());

JScrollPane north=new JScrollPane(jt);

JPanel center = new JPanel();

center.setLayout(new FlowLayout());

JPanel south=new JPanel();

south.setLayout(new FlowLayout());

center.add(lname);

center.add(jname);

center.add(lnum);

center.add(jnum);

south.add(jshow);

south.add(show);

south.add(quit);

frame.add(north,BorderLayout.NORTH);

frame.add(center,BorderLayout.CENTER);

frame.add(south,BorderLayout.SOUTH);

}

public void showMe(){

frame.setLocation(500, 300);

frame.setSize(350,280);

frame.setResizable(false);//不能拖动大小

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new NewFrame().showMe();

}

}

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

(责任编辑:IT教学网)

更多