//本来不打算回答的,要写这么多,分又这么低,不厚道啊,后来想想反正java我也是刚学,就当做练手吧。:-)
//编写一个Application程序,比较命令中给出的两个字符串是否相等,并输出比较的结果
public class StringMatch
{
public static void main(String args[])
{
Systemoutprintln(args[0]equals(args[1]));
}
}
//设计一:表示图书的book类:包括书名,作者,月销售量等属性,其中有两个构造方法:一个无参,
//一个有参,两个成员方法:setbook用于设置书名,作者月销售量等属性display用于输出书名。
class book
{
String name;
String writer;
String saleCount;
public book()
{}
public book(String name,String writer,String saleCount)
{
thisname=name;
thiswriter=writer;
thissaleCount=saleCount;
}
public void display()
{
Systemoutprintln("书名:"+name);
}
}
//设计二employer类:姓名,地址,省市,邮编等属性,并在构造方法中初始化属性,两个成员方法:
//changename用于改名字,display用于把对象完整打印,属性是受保护的,方法是公共的。
class employer
{
proceted String name;
proceted String addr;
proceted String province;
proceted String postNum;
public employer()
{}
public employer(String name,String addr,String province,String postNum)
{
thisname=name;
thisaddr=addr;
thisprovince=province;
thispostNum=postNum;
}
public void display()
{
Systemoutprintln("姓名:"+name+"地址:"+addr);
Systemoutprintln("省市:"+province+"邮编:"+postNum);
}
}
//设计三:以员工类为父类,经理,工人均继承该类,创建经理类,工人类,输出经理,工人的工资。
//在父类中编写一个成员方法Getsalary,并在子类中实现覆盖,实现多态。
class Stuff
{
protected int salary;
public int GetSalary()
{
return salary;
}
public void ShowSalary()
{
Systemoutprintln("员工工资为:"+salary);
}
}
class Manager extends Stuff
{
public void ShowSalary()
{
Systemoutprintln("经理工资为:"+salary);
}
}
class Worker extends Stuff
{
public void ShowSalary()
{
Systemoutprintln("工人工资为:"+salary);
}
}
//设计四:定义一个student类,数据成员:学号,班号,姓名,性别,年龄,
//定义一个成员方法获得学好,班号,姓名,性别,年龄。
//要求为student定义构造方法,初始化所有成员,另外增加构造方法tostring,
//把student类对象的所有信息组合成一个字符串。
class Student
{
String stuID;
String classNum;
String name;
String gender;
int age;
public Student(String stuID,String classNum,String name,String gender,int age)
{
thisstuID=stuID;
thisclassNum=classNum;
thisname=name;
thisgender=gender;
thisage=age;
}
public String[] GetStudnet()
{
String[] s=new String[5];
s[0]=stuID;
s[1]=classNum;
s[2]=name;
s[3]=gender;
s[4]=IntegertoString(age);
return s;
}
public String toString()
{
StringBuffer sb=new StringBuffer();
sbappend("学号:"+stuID);
sbappend("班号:"+classNum);
sbappend("姓名:"+name);
sbappend("性别:"+gender);
sbappend("年龄:"+age);
return sbtoString();
}
}
//设计五:定义一个接口,两个方法Method1,Method2返回值类型均为int型。
//定义一个程序实现接口要求M1的功能求5(X)次方,M2为为求两个数的较大值。
//print方法要求调用M1,M2,求M1(2),M2(2,8)
interface Itest
{
int Method1(double b);
int Method2(double c,double d);
}
class Test implements Itest
{
public int Method1(double b)
{
return (int)Mathpow(5,b);
}
public int Method2(double c,double d)
{
return (int)Mathmax(c,d);
}
void print(double b,double c,double d)
{
Systemoutprintln(Method1(b));
Systemoutprintln(Method2(c,d));
}
}
public class Demon
{
public static void main(String args[])
{
Test d=new Test();
dprint(2,2,8);
}
}
1、package nettest;
public class TestArray
{
int a[]={12,34,5,7,9,10};
public int max()
{
int j = a[1];
for(int i :a)
{
if(i > j)
{
j = i ;
}
}
return j;
}
public long avrage()
{
long j = 0l;
for(int i :a)
{
j = j + i;
}
return j/alength;
}
}
2、package nettest;
public class Person
{
String name;
int age;
Person(String name,int age)
{
thisname = name;
thisage = age;
}
public void printInfo()
{
Systemoutprintln("name = "+thisname+" age = "+thisage);
}
}
package nettest;
public class Student extends Person
{
String studentId;
Student(String name, int age)
{
super(name, age);
}
Student(String name, int age,String studentId)
{
super(name, age);
thisstudentId = studentId;
}
public void printInfo()
{
Systemoutprintln("name = "+thisname+" age = "+thisage+" StudentId =" + thisstudentId);
}
}
3、package nettest;
public class TestPrint
{
public static void main(String[] args)
{
for (int i = 1; i<10;i++)
{
for(int j = 0; j<i;j++)
{
Systemoutprint("");
}
Systemoutprintln();
}
}
}
class Circle
{
double radius;
double diameter;
double area;
public Circle()
{
radius=1;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
thisradius = radius;
}
//下面这个方法用于计算机圆的直径
public double computeDiameter()
{
return 2radius;
}
public double computeArea()
{
return MathPIradiusradius;
}
}
public class TestCircle {
public static void main(String args[])
{
Circle c1=new Circle();
Circle c2=new Circle();
Circle c3=new Circle();
c2setRadius(5);
c3setRadius(10);
Systemoutprint("第一个圆的直径为:"+c1computeDiameter());
Systemoutprintln(" 面积为:"+c1computeArea());
Systemoutprint("第二个圆的直径为:"+c2computeDiameter());
Systemoutprintln(" 面积为:"+c2computeArea());
Systemoutprint("第三个圆的直径为:"+c3computeDiameter());
Systemoutprintln(" 面积为:"+c3computeArea());
}
}
import javaawtFlowLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJTextField;
public class A implements ActionListener {
JFrame jf;
JLabel jl1;
JLabel jl2;
JLabel jl3;
JButton jb1;
JTextField jtf1;
JTextField jtf2;
JTextField jtf3;
public A(){
init();
showMe();
}
public void init(){
jf=new JFrame("拆分小数点");
jfsetLayout(new FlowLayout());
jl1=new JLabel("请输入小数");
jl2=new JLabel("整数为");
jl3=new JLabel("小数为");
jb1=new JButton("拆分");
jb1addActionListener(this);
jtf1=new JTextField(10);
jtf2=new JTextField(10);
jtf2setEditable(false);
jtf3=new JTextField(10);
jtf3setEditable(false);
jfadd(jl1);
jfadd(jtf1);
jfadd(jl2);
jfadd(jtf2);
jfadd(jl3);
jfadd(jtf3);
jfadd(jb1);
}
public void showMe(){
jfsetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
jfsetVisible(true);
jfsetLocation(300, 300);
jfpack();
}
@Override
public void actionPerformed(ActionEvent e) {
String comm=egetActionCommand();
if("拆分"equals(comm)){
String s=jtf1getText();
Systemoutprintln(s);
if(scontains("")){
String[] ss=ssplit("\\");
for (int i = 0; i < sslength; i++) {
Systemoutprintln(ss[i]);
}
jtf2setText(ss[0]);
jtf3setText(ss[1]);
}
}
}
public static void main(String[] args) {
new A();
}
}
import javaawtFlowLayout;
import javaawtGridLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javautilArrays;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJPanel;
import javaxswingJTextField;
public class B implements ActionListener {
public JFrame jf;
private JLabel jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8,jl9,jl10,jl11,jl12;
private JTextField jtf1,jtf2,jtf3,jtf4,jtf5,jtf6,jtf7,jtf8,jtf9,jtf10,jtf11,jtf12;
private JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7,jp8,jp9,jp10,jp11,jp12,jp13;
private JButton jb;
public B(){
init();
showMe();
}
public void showMe(){
jfsetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
jfsetVisible(true);
jfsetLocation(300, 300);
jfpack();
}
public void init(){
jl1=new JLabel("输入第1个数字");
jl2=new JLabel("输入第2个数字");
jl3=new JLabel("输入第3个数字");
jl4=new JLabel("输入第4个数字");
jl5=new JLabel("输入第5个数字");
jl6=new JLabel("输入第6个数字");
jl7=new JLabel("输入第7个数字");
jl8=new JLabel("输入第8个数字");
jl9=new JLabel("输入第9个数字");
jl10=new JLabel("输入第10个数字");
jl11=new JLabel("最大值为");
jl12=new JLabel("最小值为");
jl11setEnabled(false);
jl12setEnabled(false);
jtf1=new JTextField(10);
jtf2=new JTextField(10);
jtf3=new JTextField(10);
jtf4=new JTextField(10);
jtf5=new JTextField(10);
jtf6=new JTextField(10);
jtf7=new JTextField(10);
jtf8=new JTextField(10);
jtf9=new JTextField(10);
jtf10=new JTextField(10);
jtf11=new JTextField(10);
jtf11setEditable(false);
jtf12=new JTextField(10);
jtf12setEditable(false);
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jp5=new JPanel();
jp6=new JPanel();
jp7=new JPanel();
jp8=new JPanel();
jp9=new JPanel();
jp10=new JPanel();
jp11=new JPanel();
jp12=new JPanel();
jp13=new JPanel();
jb=new JButton("确定");
jbaddActionListener(this);
jp1setLayout(new FlowLayout());
jp1add(jl1);
jp1add(jtf1);
jp2setLayout(new FlowLayout());
jp2add(jl2);
jp2add(jtf2);
jp3setLayout(new FlowLayout());
jp3add(jl3);
jp3add(jtf3);
jp4setLayout(new FlowLayout());
jp4add(jl4);
jp4add(jtf4);
jp5setLayout(new FlowLayout());
jp5add(jl5);
jp5add(jtf5);
jp6setLayout(new FlowLayout());
jp6add(jl6);
jp6add(jtf6);
jp7setLayout(new FlowLayout());
jp7add(jl7);
jp7add(jtf7);
jp8setLayout(new FlowLayout());
jp8add(jl8);
jp8add(jtf8);
jp9setLayout(new FlowLayout());
jp9add(jl9);
jp9add(jtf9);
jp10setLayout(new FlowLayout());
jp10add(jl10);
jp10add(jtf10);
jp11setLayout(new FlowLayout());
jp11add(jl11);
jp11add(jtf11);
jp12setLayout(new FlowLayout());
jp12add(jl12);
jp12add(jtf12);
jf=new JFrame("最大值最小值");
jfsetLayout(new GridLayout(13, 1));
jfadd(jp1);
jfadd(jp2);
jfadd(jp3);
jfadd(jp4);
jfadd(jp5);
jfadd(jp6);
jfadd(jp7);
jfadd(jp8);
jfadd(jp9);
jfadd(jp10);
jfadd(jp11);
jfadd(jp12);
jfadd(jb);
}
@Override
public void actionPerformed(ActionEvent e) {
String comm=egetActionCommand();
if("确定"equals(comm)){
int i1=IntegerparseInt(jtf1getText());
int i2=IntegerparseInt(jtf2getText());
int i3=IntegerparseInt(jtf3getText());
int i4=IntegerparseInt(jtf4getText());
int i5=IntegerparseInt(jtf5getText());
int i6=IntegerparseInt(jtf6getText());
int i7=IntegerparseInt(jtf7getText());
int i8=IntegerparseInt(jtf8getText());
int i9=IntegerparseInt(jtf9getText());
int i10=IntegerparseInt(jtf10getText());
int arr[]={i1,i2,i3,i4,i5,i6,i7,i8,i9,i10};
Arrayssort(arr);
int max=arr[9];
int min=arr[0];
jtf11setText(max+"");
jtf12setText(min+"");
}
}
public static void main(String[] args) {
new B();
}
}
import javaawtFlowLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javautilArrays;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJTextField;
public class C implements ActionListener {
private JFrame jf;
private JLabel jl1,jl2;
private JTextField jtf1,jtf2;
JButton jb1;
public C(){
init();
showMe();
}
public void init(){
jf=new JFrame("字母排序");
jfsetLayout(new FlowLayout());
jl1=new JLabel("请输入字母");
jl2=new JLabel("排序后");
jb1=new JButton("排序");
jb1addActionListener(this);
jtf1=new JTextField(10);
jtf2=new JTextField(10);
jtf2setEditable(false);
jfadd(jl1);
jfadd(jtf1);
jfadd(jl2);
jfadd(jtf2);
jfadd(jb1);
}
public void showMe(){
jfsetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
jfsetVisible(true);
jfsetLocation(300, 300);
jfpack();
}
@Override
public void actionPerformed(ActionEvent e) {
String comm=egetActionCommand();
if("排序"equals(comm)){
String s=jtf1getText();
char[] c=new char[slength()];
if(sendsWith("#")){
for (int i = 0; i < slength(); i++) {
c[i]=scharAt(i);
}
}
Arrayssort(c);
String ss="";
for (int i = 0; i < clength; i++) {
ss=ss+c[i];
}
jtf2setText(sssubstring(1));
}
}
public static void main(String[] args) {
new C();
}
}
都是有界面的,写界面不难 就是很麻烦。。。我自己写的 都是可以直接运行的,有什么问题可以再问我。。。
以上就是关于java 程序设计题全部的内容,包括:java 程序设计题、JAVA程序设计题!请高手帮我解答!、java 程序设计题目解答等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)