Zion小程序,Java小程序

1 , Java小程序 super("Star flight street 110");指 执行父类的构造方法,就是public HouseHold(String add) address=add;}结果就是address="Star flight street 110"public HouseHold(String add)调用了父类的这个构造函数
2,JAVA小程序abstract class Shapeabstract int zhouchang();abstract int sque();}public class Testpublic static void main(String[] args)Shape[] sh =for (int i = 0; i < sh.length; i++)if (sh[i] instanceof Circle)System.out.println("圆的面积为:" + sh[i].sque());System.out.println("圆的周长为:" + sh[i].zhouchang());continue;}if (sh[i] instanceof Square)System.out.println("正方形的面积为:" + sh[i].sque());System.out.println("正方形的周长为:" + sh[i].zhouchang());continue;}if (sh[i] instanceof Rect)System.out.println("长方形的长宽差为:" + ((Rect) sh[i]).cha());System.out.println("长方形的面积为:" + sh[i].sque());System.out.println("长方形的周长为:" + sh[i].zhouchang());}}} }class Rect extends Shapeprivate int width;private int length;public Rect()}public Rect(int width, int length)this.width = width;this.length = length;}public int zhouchang()return 2 * (width + length);}public int sque()return width * length;}public int cha()return length - width;} }class Circle extends Shapeprivate static float PI = 3.14f;private int rad;Circle()}Circle(int rad)this.rad = rad;}int sque()return (int) (2 * PI * rad);}int zhouchang()return (int) (PI * rad * rad);}}class Square extends Rectprivate int width;Square()}Square(int width)this.width = width;}public int sque()return 4 * width;}public int zhouchang()return width * width;}}刚才没有看到要求正方形要继承矩形,现在修改好了,应该没有什么问题了【Zion小程序,Java小程序】
3 , java小程序还是用了异常,因为需要判断输入的是否为数字 。异常还是很简单的package org.my.wq;import java.io.IOException;import java.util.Random;public class Guess public static void main(String[] args) throws IOException Random ran = new Random(); //这里可以修改猜的数字范围 int answer = ran.nextInt(5000); System.out.print("请猜测公主电动车的价格:"); byte[] b = new byte[1024]; int count = 0; while (true) //这里可以修改总共猜的次数 if (count == 4) System.out.println("4次都没有猜对 , 下次努力吧 。正确答案是" + answer); } int n = System.in.read(b); int s = 0; try s = Integer.parseInt(new String(b, 0, n).trim()); } catch (Exception e) e.printStackTrace(); System.out.println("请输入数字"); continue; } if (s == answer) System.out.println("恭喜猜对了!"); } else if (s < answer) System.out.println("再大一点"); System.out.println("再猜一次吧:"); } else if (s > answer) System.out.println("再小一点"); System.out.println("再猜一次吧:"); } count++ ; } }}第一个是:import javax.swing.*;public class test public static void main( string args[]) string input = joptionpane.showinputdialog("请输入一个时间:"); int time = integer.parseint(input); int hour = time / 60; int minute = (time % 60); joptionpane.showmessagedialog(null,hour+"小时"+minute+"分钟"); system.exit( 0 ); }}直接复制粘贴 。把这个保存为test.java,然后编译 。注意大小写 。第二个是:import javax.swing.*;public class test public static void main( string args[]) string input = joptionpane.showinputdialog("请输入工作每小时的报酬:"); int pay = integer.parseint(input); input = joptionpane.showinputdialog("请输入工作小时数:"); int hour = integer.parseint(input); input = joptionpane.showinputdialog("请输入税率(0.00):"); float rate = float.parsefloat(input); string output; output = "每小时工资:" + pay + "\n工作小时数:" + hour + "\n总收入:" + (pay * hour) + "\n缴税金额:" + (pay*hour*rate) + "\n净利润:" + (pay*hour*(1-rate)); joptionpane.showmessagedialog(null,output); system.exit( 0 ); }}这程序中在输入税率时不以%5输入  , 而是以0.05的形式输入 。因为我还没有找到能把%5转换成float型数的函数 。所以这一点很抱歉 。望谅解 。^_^同样的把这个保存成test.java即可编译 。
4,JAVA小程序JAVE的,C+的可以吗?import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;import javax.swing.border.*;public class Englishword extends JFrame{JTextField jtfDelay;//时间输入框JButton btDict;//按钮“更改词库”JButton btStart;//按钮“开始”JLabel showLabel;//显示单词内容框File dict;//词库文件BufferedReader filereader;//词库文件读取器Thread timerdelay;//延时器public Englishword(){super("英语背单词");init();setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}//初始化各组件private void init(){//控制组件JLabel label = new JLabel("延时(毫秒)");jtfDelay = new JTextField(5);jtfDelay.setText("1000");//默认显示1000毫秒btDict = new JButton("选择词库");btStart = new JButton("开始");btStart.setEnabled(false);//初始时“开始”按钮不可用,只有选择词库后才可用JPanel controlPane = new JPanel();controlPane.add(label);controlPane.add(jtfDelay);controlPane.add(btDict);controlPane.add(btStart);//将各组件添加到窗口this.getContentPane().setLayout(new BorderLayout());this.getContentPane().add(controlPane, BorderLayout.NORTH);showLabel = new JLabel("背单词");showLabel.setBorder(new LineBorder(java.awt.Color.GRAY));this.getContentPane().add(showLabel, BorderLayout.CENTER);//timerdelaytimerdelay = new Thread(new Delay());//两个按钮动作//点击选择词库按钮,弹出文件选择框btDict.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {JFileChooser cho = new JFileChooser();if(cho.showOpenDialog(null)==JFileChooser.APPROVE_OPTION){dict = cho.getSelectedFile();//取得用户选择的文件//关闭原有的文件读取器并停止原来的延时器try {filereader.close();filereader = null;timerdelay.join();} catch (Exception e1) {}//根据新选择的文件初始化文件读取器try {filereader = new BufferedReader(new FileReader(dict));btStart.setEnabled(true);} catch (FileNotFoundException e1) {e1.printStackTrace();}}}});//未完,再下面补充这个JAVA的小程序可是不小啊!~你居然叫他小程序~!!!!!!!!1

    推荐阅读