java语言程序设计,设计一个java程序

1,设计一个java程序這個class必須implement MouseListener, 還要寫 mouseEntered, mouseExited.注意字母別拼錯, 大小寫都要對, 狄惨獙?
2,JAVA程序设计我直接写核心的代码class Common{Common(int m,int n){a = m;b = n;}public void seta(int m){a= m;}public void setb(int n){b = n;}public int geta(){return a;}public int getb(){return b;}public abstract int getSpeed();private int a;private int b;}class car extends Common{car(int m , int n){super(m,n);}public int getSpeed(){return a+b;}public void print(){System.out.println("a+b的值:"+getSpeed());}}题目说得不详细
3,什么是JAVA语言程序设计Java,是一种可以撰写跨平台应用软件的面向对象的程序设计语言,由Sun公司的詹姆斯·高斯林(James Gosling)等人于1990年代初开发 。它最初被命名为Oak , 目标设置在家用电器等小型系统的编程语言 , 来解决诸如电视机、电话、闹钟、烤面包机等家用电器的控制和通讯问题 。由于这些智能化家电的市场需求没有预期的高 , Sun放弃了该项计划 。就在Oak几近失败之时,随着互联网的发展,Sun看到了Oak在计算机网络上的广阔应用前景,于是改造了Oak,在1995年5月以“Java”的名称正式发布了 。Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言 。Java编程语言的风格十分接近C++语言 。继承了C++ 语言面向对象技术的内核,Java舍弃了C++语言中容易引起错误的指针(以引用取代)、运算符重载(operator overloading)、多重继承(以接口取代)等特性,增加了垃圾回收器功能用于回收不再被引用的对象所占据的内存空间 。在Java SE 1.5版本中Java又引入了泛型编程(Generic Programming)、类型安全的枚举、不定长参数和自动装/拆箱等语言特性 。Java不同于一般的编译运行计算机语言和解释执行计算机语言 。它首先将源代码编译成字节码(bytecode),然后依赖各种不同平台上的虚拟机来解释执行字节码,从而实现了“一次编译、到处执行”的跨平台特性 。不过,这同时也在一定程度上降低了Java程序的运行效率 。但在J2SE1.4.2发布后,Java的运行速度有了大幅提升 。与传统程序不同Sun公司在推出Java之际就将其作为一种开放的技术 。全球数以万计的Java开发公司被要求所设计的Java软件必须相互兼容 。“Java语言靠群体的力量而非公司的力量”是Sun公司的口号之一,并获得了广大软件开发商的认同 。这与微软公司所倡导的注重精英和封闭式的模式完全不同 。java编程语言的解释是:Java编程语言是个简单、面向对象、分布式、解释性、健壮、安全与系统无关、可移植、高性能、多线程和动态的语言 。java是一种简单的,面向对象的,分布式的,解释型的,健壮安全的,结构中立的 , 可移植的,性能优异、多线程的动态语言 。当1995年sun推出java语言之后,全世界的目光都被这个神奇的语言所吸引 。那么java到底有何神奇之处呢?java语言其实最早诞生于1991年 , 起初被称为oak语言 , 是sun公司为一些消费性电子产品而设计的一个通用环境 。他们最初的目的只是为了开发一种独立于平台的软件技术,而且在网络出现之前 , oak可以说是默默无闻,甚至差点夭折 。但是,网络的出现改变了oak的命运 。在java出现以前,internet上的信息内容都是一些乏味死板的html文档 。这对于那些迷恋于web浏览的人们来说简直不可容忍 。他们迫切希望能在web中看到一些交互式的内容,开发人员也极希望能够在web上创建一类无需考虑软硬件平台就可以执行的应用程序 , 当然这些程序还要有极大的安全保障 。对于用户的这种要求,传统的编程语言显得无能为力 。sun的工程师敏锐地察觉到了这一点,从1994年起,他们开始将oak技术应用于web上 , 并且开发出了hotjava的第一个版本 。当sun公司1995年正式以java这个名字推出的时候,几乎所有的web开发人员都心生感叹:噢,这正是我想要的!于是java成了一颗耀眼的明星,丑小鸭一下了变成了白天鹅 。【java语言程序设计,设计一个java程序】
4,JAVA程序设计abstract class Shapedouble perimeter;double area;}class Triangle extends Shapedouble rightAngleSide;double AdjacentAngleEdge;double hypotenuse;public void setRightAngleSide(double rightAngleSide)this.rightAngleSide = rightAngleSide;}public void setAdjacentAngleEdge(double adjacentAngleEdge)AdjacentAngleEdge = adjacentAngleEdge;}public void setHypotenuse(double hypotenuse)this.hypotenuse = hypotenuse;}public boolean checkTriangle()double r = this.rightAngleSide;double a = this.AdjacentAngleEdge;double h = this.hypotenuse;return (r * r + a * a) == (h * h);}}class Rectangle extends Shapedouble length;double width;public Rectangle(double length, double width)this.length = length;this.width = width;}public double getPerimeter()return (this.length + this.width) * 2;}public double getArea()return this.length * this.width;}}class Circle extends Shapedouble radius;public Circle()}public Circle(double radius, double perimeter, double area)this.radius = radius;}public double getPerimeter()return Math.PI * this.radius * 2;}public double getArea()return Math.PI * this.radius * this.radius;}}public class Testpublic static void main(String[] args)}}5,JAVA程序设import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Calculator{public static void main(String[] args){CalculatorFrame frame = new CalculatorFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}}/**A frame with a calculator panel.*/class CalculatorFrame extends JFrame{public CalculatorFrame(){setTitle("Calculator");CalculatorPanel panel = new CalculatorPanel();add(panel);pack();}}/**A panel with calculator buttons and a result display.*/class CalculatorPanel extends JPanel{public CalculatorPanel(){setLayout(new BorderLayout());result = 0;lastCommand = "=";start = true;// add the displaydisplay = new JButton("0");display.setEnabled(false);add(display, BorderLayout.NORTH);ActionListener insert = new InsertAction();ActionListener command = new CommandAction();// add the buttons in a 4 x 4 gridpanel = new JPanel();panel.setLayout(new GridLayout(4, 4));addButton("7", insert);addButton("8", insert);addButton("9", insert);addButton("/", command);addButton("4", insert);addButton("5", insert);addButton("6", insert);addButton("*", command);addButton("1", insert);addButton("2", insert);addButton("3", insert);addButton("-", command);addButton("0", insert);addButton(".", insert);addButton("=", command);addButton("+", command);add(panel, BorderLayout.CENTER);}/**Adds a button to the center panel.@param label the button label@param listener the button listener*/private void addButton(String label, ActionListener listener){JButton button = new JButton(label);button.addActionListener(listener);panel.add(button);}/**This action inserts the button action string to theend of the display text.*/private class InsertAction implements ActionListener{public void actionPerformed(ActionEvent event){String input = event.getActionCommand();if (start){display.setText("");start = false;}display.setText(display.getText() + input);}}/**This action executes the command that the buttonaction string denotes.*/private class CommandAction implements ActionListener{public void actionPerformed(ActionEvent event){String command = event.getActionCommand();if (start){if (command.equals("-")){display.setText(command);start = false;}elselastCommand = command;}else{calculate(Double.parseDouble(display.getText()));lastCommand = command;start = true;}}}/**Carries out the pending calculation.@param x the value to be accumulated with the prior result.*/public void calculate(double x){if (lastCommand.equals("+")) result += x;else if (lastCommand.equals("-")) result -= x;else if (lastCommand.equals("*")) result *= x;else if (lastCommand.equals("/")) result /= x;else if (lastCommand.equals("=")) result = x;display.setText("" + result);}private JButton display;private JPanel panel;private double result;private String lastCommand;private boolean start;}//参见<>这个吗 我这有个 但是很简单需要吗?关于到swing开发的呀,多看些资料import java.util.HashMap;import java.util.Map;public class Test {private static String WORD = "0"; //定义单词KEYprivate static String SENTENCE = "1"; //定义句子KEY/*** 分析一个字符串有多少个句子的单词的方法* @param str 要分析的字符串* @return map*/public static MapgetCount(String str) { str = str.replace(".", "#"); //把所有的.替换成# str = str.replace("?", "#"); //把所有的?替换成# str = str.replace("!", "#"); //把所有的!替换成# //这样所有的名子都是用#分割的了 int wordCount = str.split(" ").length; //按空格分割字符串,字符数组的长度就是单词的个数 int sentenceCount = str.split("#").length; //按#分割字符 , 字符数组的长度就是句子的个数 Map map = new HashMap(); map.put(WORD, wordCount); //把单词个数风装到map中 map.put(SENTENCE, sentenceCount); //把句子个数风装到map中 return map; } /** * 测试方法 * @param args */ public static void main(String[] args) { Map map = getCount("hello word!"); System.out.println("单词数量: "+map.get(WORD)); System.out.println("句子数量: " + map.get(SENTENCE)); } } 答案补充 JDK的API中String这个类有2个方法被我上面有例子所用到:replace和split 。replace可以把字符串中的字符以制定的字符替代 。split可以把字符串分割成数组,并且可以指定用什么字符分割 。这样2个方法结合起来就很容易得到你想要的结果了 。不必用循环和判断 , 直接把分割后数组的长度取得就可以了 。上面的例子你可以直接运行,当然文件名要起成Test.java

    推荐阅读