java程序设计实训代码 java程序设计实训代码是什么

写个简单的java程序!在线等 。//问题java程序设计实训代码:求一个长方形的周长和面积
/*以面向过程的程序设计方式思考:
1.确定长方形的周长和面积的算法java程序设计实训代码;
2.编写两个方法(函数)分别计算长方形的周长和面积;
3.求周长的方法(函数)和求面积的方法(函数)需要两个参数 ,
分别是长方形的长和宽*/
//面向过程的程序设计代码:
/*classRectangle
{
static
float
perimeter(float
length,floatwidth)
{
return
2*(length width);
}
static
float
area(float
length,
float
width)
{
return
length*width;
}
public
static
void
main(String[]
args)
{
System.out.println("the
perimeter
is
="
perimeter(3.123f,4.267f));
System.out.println("the
area
is="
area(3.123f,4.267f));//使用f来表示浮点
}
}*/
/*以面向对象的程序设计方式思考:
1.一个长方形可以看成是一个长方形对象;
2.一个长方形对象有两个状态(长和宽)和两个行为(求周长和面积)
3.将所有长方形的共性抽取出来,设计一个长方形的类
4.通过长方形对象的行为,就可以求出某个具体的长方形的周长和面积*/
//面向对象的程序设计代码:
classRectangle
{
float
l,h;//有两个状态,即两个成员变量
float
perimeter()
{
return
2*(l h);
}
float
area()
{
return
l*h;
}
public
static
void
main(String[]
args)
{
Rectangle
rect1=newRectangle();
Rectangle
rect2=newRectangle();
rect1.l=10.13f;
rect1.h=5.74f;
rect2.l=12.21f;
rect2.h=24.13f;
System.out.println("Theperimeter
is
="
rect1.perimeter());
System.out.println("The
area
is="
rect1.area());
System.out.println("Theperimeter
is
="
rect2.perimeter());
System.out.println("The
area
is="
rect2.area());
}
/*K:\Java\try\lesson3javacRectangle.java
K:\Java\try\lesson3java
Rectangle
The
perimeter
is
=31.74
The
area
is
=58.1462
The
perimeter
is
=72.68
The
area
is
=294.6273
*/
}
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实验代码public interface Student {
// 该方法用于表示不同阶段的学生在学习数学课程时的不同内容
public abstract void studyMath();
// 该方法用于表示不同阶段的学生的英语水平
public abstract void studyEnglish();
}
public class PrimarySchoolStudent implements Student {
@Override
public void studyMath() {
System.out.println("小学生在学习数学课程时,主要学习加减法 , 数学表达式等基础知识 。");
}
@Override
public void studyEnglish() {
System.out.println("小学生在学习英语时,主要学习词汇,基本句型,基本语法等基础知识 。");
}
}
public class MiddleSchoolStudent implements Student {
@Override
public void studyMath() {
System.out.println("中学生在学习数学课程时 , 主要学习初等函数,代数方程等基础知识 。");
}
@Override
public void studyEnglish() {
System.out.println("中学生在学习英语时,主要学习阅读理解,听力理解 , 口语交流等能力 。");
}
}
public class CollegeStudent implements Student {
@Override
public void studyMath() {
System.out.println("大学生在学习数学课程时,主要学习高等数学,概率论 , 数值计算等专业知识 。");
}
@Override
public void studyEnglish() {
System.out.println("大学生在学习英语时,主要学习专业英语,商务英语,英文写作等能力 。");
}
}
public class Main {
public static void main(String[] args) {
求大神用Java编写出这个程序 , 要有具体代码,万分感激,定采纳按照你的要求编写的JavaGUI程序如下:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class HH extends JFrame implements ActionListener{
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JTextField jtf=new JTextField(20);
JButton jb1=new JButton("显示");
JButton jb2=new JButton("清除");
HH(){
jb1.addActionListener(this);
jb2.addActionListener(this);
jp1.setLayout(new GridLayout(2,1));
jp3.add(jtf);
jp2.add(jb1);jp2.add(jb2);
jp1.add(jp3);jp1.add(jp2);
getContentPane().add(jp1);
setSize(300, 120);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1){
jtf.setText("java程序设计");
}
if(e.getSource()==jb2){
jtf.setText("");
}
}
public static void main(String[] args) {
【java程序设计实训代码 java程序设计实训代码是什么】new HH();
}
}
求一个简单java程序代码,谢谢public class TestStar {
public static void main(String[] args) {
String star = "*";
for (int i = 0; i5; i) {
if (i == 0) {
System.out.print(" "star);
System.out.println();
}
if (i == 1) {
for (int z = 0; z4; z) {
System.out.print(" "star);
}
System.out.println();
}
if (i == 2) {
System.out.print(" ");
for (int x = 0; x3; x) {
System.out.print(" "star);
}
System.out.println();
}
if (i == 3) {
for (int y = 0; y2; y) {
System.out.print(" "star" ");
}
}
}
}
}
是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧java程序设计实训代码?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给java程序设计实训代码你写一个)
关于java程序设计实训代码和java程序设计实训代码是什么的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读