java在线学习java银行管理系统代码谁有啊?给个代码被 大神在哪里啊

生手学习,求各位大神看看给个代码
&来源:读书人网&【读书人网():综合教育门户网站】
新手学习,求各位大神看看给个代码有一个水果箱(box),箱里有水果(Fruit),每一种水果都有不同的颜色和重量,
新手学习,求各位大神看看给个代码有一个水果箱(box),箱里有水果(Fruit),每一种水果都有不同的颜色和重量,水果有苹果(Apple),橘子(Orange),梨(Pear)。每个苹果都有不同的颜色和重量,每个橘子都有不同的颜色和重量,每个梨都有不同的颜色和重量。可以向水果箱里添加水果(addFruit),也可以取出水果(getFruit),还可以显示水果的重量和颜色,写出实现这样方法的代码,要求实现上述功能! &
求各位大神给个代码啊!谢谢![解决办法]Java codeclass Box{
private List&Fruit& fruitList = new ArrayList&Fruit&();
Box(Fruit fruit){
this.fruit =
public void
addFruit(Fruit fruit){}
public void getFruit(Fruit fruit){}
public String showFruit(Fruit fruit){return fruit.getColor() + fruit.getWeight();}}class Fruit{
public String getColor() {
public void setColor(String color) {
this.color =
public double getWeight() {
public void setWeight(double weight) {
this.weight =
}}[解决办法]呵呵 楼主我改下代码,这样的话你更方便了,你如果想要添加一种水果比如桃子的话,你要改的代码很少,就只要继承Fruit类然后new一个桃子就OK了其他代码都不用动,程序会自动帮你识别重量,颜色以及名字的Java codepackage com.djk.import java.lang.reflect.Fimport java.util.ArrayL/** * 水果接口 * @author Administrator * */ abstract class Fruit {
private StringBuffer sb = new StringBuffer();
public String toString()
//水果的重量
String weigth
//水果的颜色
String color =
//水果的全称包括包名字
String name =
//水果的英语名字
String fruitname =
name = this.getClass().getName();
//如果name包括包名的话
if(name.lastIndexOf(&.&)!=-1)
fruitname = name.substring(name.lastIndexOf(&.&)+1,name.length());
fruitname =
//利用反射拿到fruit的私有属性
field1 = this.getClass().getDeclaredField(&weight&);
field1.setAccessible(true);
field2 = this.getClass().getDeclaredField(&color&);
field2.setAccessible(true);
//得到重量
weigth = (String)field1.get(this);
//得到颜色
color = (String)field2.get(this);
catch (Exception e)
System.out.println(&error&);
return sb.append(&这个&).append(fruitname).append(&的颜色是&).append(color).append(&重量是:&).append(weigth).toString();
* @author Administrator
*/ class Apple extends
public Apple(String weight,String color)
this.weight =
this.color =
public String getWeight() {
public void setWeight(String weight) {
this.weight =
public String getColor() {
public void setColor(String color) {
this.color =
* @author Administrator
*/ class Orange extends
public Orange(String weight,String color)
this.weight =
this.color =
public String getWeight() {
public void setWeight(String weight) {
this.weight =
public String getColor() {
public void setColor(String color) {
this.color =
* @author Administrator
*/ class Pear extends
public Pear(String weight,String color)
this.weight =
this.color =
public String getWeight() {
public void setWeight(String weight) {
this.weight =
public String getColor() {
public void setColor(String color) {
this.color =
* 水果箱子
* @author Administrator
*/class FruitBox{
//集合用来装水果的
private ArrayList&Fruit& fruitList = new ArrayList&Fruit&();
//用来放水果
public FruitBox addFruit(Fruit fruit)
fruitList.add(fruit)?this:
//用来取水果的集合
public ArrayList&Fruit& getFruit()
if(fruitList.isEmpty())
return fruitL
}/** *测试类
* @author Administrator * */public class FruitTest {
public static void main(String[] args)
//水果箱子
FruitBox fruitBox = new FruitBox();
Fruit a = new Apple(&23&, &红色&);
Fruit d = new Apple(&29&, &青色&);
Fruit b = new Orange(&24&,&黄色&);
Fruit c = new Pear(&28&,&黄色&);
//把水果都放入箱子中
fruitBox.addFruit(a).addFruit(d).addFruit(b).addFruit(c);
//把箱子中的水果拿出来
ArrayList&Fruit& fruitList = fruitBox.getFruit();
for(Fruit fruit :fruitList)
System.out.println(fruit);
[解决办法]我这个可能不是你想要的,我只是一时兴起,回顾了一下生产者与消费者的问题。Java codepackage com.zf.import java.util.ArrayLpublic class Test7 {
public static void main(String[] args) throws Exception{
final FruitBasket basket = new FruitBasket();
final Fruit apple = new Apple(&红色&, 300);
final Fruit pear = new Pear(&黄色&, 200);
for(int i = 0 ; i & 10 ; i++){ //模拟 10 人取
new Thread(new Runnable() {
public void run() {
int x = 0 ;
while(true)
basket.addFruit(++x % 2 == 0 ? apple : pear);
} catch (Exception e) {
e.printStackTrace();
}).start();
new Thread(new Runnable() {
public void run() {
while(true)
basket.getFruit();
} catch (Exception e) {
e.printStackTrace();
}).start();
}}//果篮class FruitBasket extends ArrayList&Fruit&{
private static final long serialVersionUID = 1L;
int max = 10 ;
public FruitBasket(){};
public FruitBasket( int max ){
this.max =
public synchronized void addFruit(Fruit fruit) throws Exception{
while(size() &= max){
System.out.println(&篮子已经满了,请稍等!&);
add(fruit);
notifyAll();
System.out.println(&放入水果成功,当前水果总数:& + size());
public synchronized Fruit getFruit() throws Exception{
while(size() &= 0){
System.out.println(&篮子已经空了,请稍等!&);
Fruit fruit = remove(0);
System.out.println(&取出水果成功\t:& + fruit + &\t当前水果总数:& + size());
notifyAll();
}}//抽象父类abstract class Fruit{
protected S
abstract void setColor(String color) ;
abstract String getColor() ;
abstract double getWeight();
abstract void setWeight(double weight) ;
public String toString() {
return &颜色:& + this.color + & ,
重量:& + this.
}class Apple extends Fruit{
public Apple(){}
public Apple(String color , double weight){
this.color =
this.weight =
void setColor(String color) {
this.color =
String getColor() {
return this.
double getWeight() {
return this.
void setWeight(double weight) {
this.weight =
public String toString() {
return &苹果\t& + super.toString();
}class Pear extends Fruit{
public Pear(){}
public Pear(String color , double weight){
this.color =
this.weight =
public void setColor(String color) {
this.color =
public String getColor() {
return this.
public double getWeight() {
return this.
public void setWeight(double weight) {
this.weight =
public String toString() {
return &梨子\t& + super.toString();
}}[解决办法]
简化一点,应该为这样Java code//抽象父类abstract class Fruit{
public Fruit(String name){
this.name =
public String getName() {
public String getColor() {
public void setColor(String color) {
this.color =
public double getWeight() {
public void setWeight(double weight) {
this.weight =
public String toString() {
return &类型:& + this.name + &,颜色:& + this.color + & ,
重量:& + this.
}}class Apple extends Fruit{
public Apple(){
super(&苹果&);
}}class Pear extends Fruit{
public Pear(){
super(&梨子&);
}}[解决办法]Java codepackage fruitBimport java.util.ArrayLpublic class FruitBoxDemo {
public static void main(String args[]){
//水果箱子
FruitBox fruitBox = new FruitBox();
Fruit a = new Apple(23,&红色&);
Fruit d = new Apple(29,&青色&);
Fruit b = new Orange(24,&黄色&);
Fruit c = new Pear(28,&黄色&);
//把水果都放入箱子中
fruitBox.addFruit(a).addFruit(d).addFruit(b).addFruit(c);
//把箱子中的水果拿出来
ArrayList&Fruit& fruitList = fruitBox.getFruit();
for(Fruit fruit:fruitList){
System.out.println(fruit);
}}class Fruit{
public Fruit(){
public Fruit(Integer weight,String color){
this.color =
this.weight =
public String toString(){
StringBuffer sb = new StringBuffer();
sb.append(&这个&).append(this.getClass().getName()).append(&的颜色是:&).append(color).append(& 重量是:&).append(weight);
return sb.toString();
public Integer getWeight() {
public void setWeight(Integer weight) {
this.weight =
public String getColor() {
public void setColor(String color) {
this.color =
}}class Apple extends Fruit{
public Apple(Integer weight,String color){
super(weight,color);
}}class Orange extends Fruit{
public Orange(Integer weight,String color){
super(weight,color);
}}class Pear extends Fruit{
public Pear(Integer weight,String color){
super(weight,color);
}}/*水果箱子*/class FruitBox{
//集合用来装水果的
private ArrayList&Fruit& fruitList = new ArrayList&Fruit&();
//用来放水果
public FruitBox addFruit(Fruit fruit){
fruitList.add(fruit);
//用来取水果的集合
public ArrayList&Fruit& getFruit(){
return fruitLjava 求大神帮忙改个代码 已经搞好大部分了 还有点问题 跪求(已经求助好几天了)_百度知道
java 求大神帮忙改个代码 已经搞好大部分了 还有点问题 跪求(已经求助好几天了)
&quot:31};name&一年级一班&quot.}的外面2;1-2&);second_id&二年级&;:&;id&people&quot,
&second_name&:[{
&first_id&:1-1;;,&,
&quot:&first_id&people&高中&1-1-2&;&;:41
&quot,&;people\people&,
&third_id&quot:&,{
&quot,{ &quot, &name&统计2&;;1-1&quot,&id&quot:&quot,&quot:1;id&quot,
&;;;中学&;;name&people&quot:&quot:&;:1;;:&quot:&first_name&quot:21},
&&quot:&中学&name&quot:111}]&quot:&quot:&quot:&1+1&people&quot:&;people&second_id&second_id&2—1&name&一年级&third_id&;first_id&,统计2应该在整个id为1这个{:&1-1-1&quot:31
}]源码的问题;third_name&name&;统计1&quot:21
}, &;name&quot,{&;;;中学&二年级一班&;2—1+1&:&;people&;;second_id&,&1-2-2&id&quot,&quot,{
&&quot:1-2-1,
&;, &children&;&quot,
&name&id&name&:&people1&#92:11
}] };id&;;2—1-1&,\name&quot:&quot,
&quot:11}:&second_name&,
&;third_id&;id&;;;;first_name&,&高中&;;:62
};二年级&people&third_id&quot,
&quot:31,&quot:&;一年级一班&name&quot,
&quot,&;;,&quot:&people&quot:&quot:&;统计1&quot:&;:1-1-2:&quot:31
]};;second_id&quot,{
&quot:1-1;;;:&;;1-2-2&quot:10
};:&quot,&quot.统计1和2的位置有点不对,{
&一年级&quot:&id&二年级一班&second_name&;;:&quot:&1-2-1&quot:[{
&一年级二班&quot,]对上面json数组遍历成下面的样子[{ &quot,
&,&quot:&people&quot:&quot,&children&quot:&quot:&\统计2&id&;,&:&,
&quot.如果再加个属性(&people&first_id&;;:&quot,
&second_name&quot:&;二年级&quot,&,&quot,
&quot,&quot,&一年级一班&;一年级&;一年级二班&quot:&quot.:2;:[{
&;children&:21
}] };third_name&;name&;;third_name&中学&中学&quot:&quot,统计1应该在中学下面这个children的外面;first_name&;;;1&people&quot,{
&quot:1-1-1;;;;:1:1;children&quot:1-2,{
&quot:&quot,&,&;third_name&;,&quot,&;,&quot:[{
&quot:&:[{&quot,&quot:31
}] }:&name&一年级一班&,&quot,
&;second_name&children&2&quot:&,&2+1&quot, {
&quot,&quot:&;name&quot,
&id&;;,&quot,&统计1&一年级&name&;id&quot:1-2;id&quot:20
};一年级&1-1+1&1-2+1&first_id&quot,
&id&first_name&third_name&quot,
&people&quot:&quot,{
&;;,{&二年级一班&quot:1;:10};:2-1-1:&quot:20}:&people&;first_name&;:2-1,{&二年级一班&third_id&;people&quot, &,&;,{&,计算两个peoplejson数组
&#47.com/share/home://pan?uk=&view=share#category/type=0test2.jar是源码test.jar里有jar包&#47://pan./share/home?uk=&view=share#category/type=0" target="_blank">http<a href="http
提问者采纳
&&#92.如果再加个属性(&quot:111}]&;;&people1&#92;people&#92:31;&);;&quot,&#922,计算两个people
有试代码?试了就知道
就是多了个统计1,每遍历一次,设置一次
我改好了,下午等你回复没回复我。。哟就下班了。
额,不好意思哈,下午有事得
可以发下代码看看?
可以看下代码怎么改的?
提问者评价
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Android: FATAL EXCEPTION: main java.lang.NullPointerException 求大神看看哪里错了-中国学网-中国IT综合门户网站
> Android: FATAL EXCEPTION: main java.lang.NullPointerException 求大神看看哪里错了
Android: FATAL EXCEPTION: main java.lang.NullPointerException 求大神看看哪里错了
转载 编辑:李强
为了帮助网友解决“Android: FATAL EXCEP”相关的问题,中国学网通过互联网对“Android: FATAL EXCEP”相关的解决方案进行了整理,用户详细问题包括:RT,我想知道:Android: FATAL EXCEPTION: main java.lang.NullPointerException 求大神看看哪里错了,具体解决方案如下:解决方案1:
报空指针了啊,你点击程序会自动跳转到错误到那里,你就检查那一行到几个变量是否为空,就能解决问题了
通过对数据库的索引,我们还为您准备了:问:总共就2个class,ss 知道是18行出错,不知道怎么改 http://pan.baidu.co...答:给个错误提示么,估计是包名问题。你在清单文件里,根本没有给你第二个activity注册,当然报错。===========================================问:我之前还可以运行的,后面新建了个写menu背景色的文件后,就运行不了,...答:看下你的MainActivity的配置文件,看了下你的报错信息好像不是程序上的问题。 就是检查下Minafeast那个全局配置文件。估计你的问题就在这里,自习的看看是不是配置上出现了少元素或者结构位置不对,或者activity没有注册的问题。===========================================问:主JAVA文件: package your. import java.io.IOE import ...答:下次问这种问题,请把异常信息一起发出来 20行空指针。。。。这不是说的很明确了么? 看看你的button是不是null吧===========================================问:主JAVA文件: package your. import java.io.IOE import ...答:报空指针了啊,你点击 程序会自动跳转到错误到那里,你就检查那一行到几个变量是否为空,就能解决问题了 ===========================================问:主JAVA文件: package your. import java.io.IOE import ...答:ERROR/AndroidRuntime(860): FATAL EXCEPTION: main 10-08 00:37:01.934这样写没有错,空指针应该是其它地方的问题。 button没取到,是null ,===========================================问:04-03 05:26:06.691: E/AndroidRuntime(1452): FATAL EXCEPTION: Thread...答:错误给出的很明显,是有一个布局文件中第39行出现了问题,Error inflating class gwj.iss.sric.view.GameView看看这个包名是不是有问题~===========================================问:04-03 05:26:06.691: E/AndroidRuntime(1452): FATAL EXCEPTION: Thread...答:空指针异常!具体的错误还要看代码才知道!===========================================问:06-10 22:14:29.940: E/AndroidRuntime(862): FATAL EXCEPTION: main 06...答:菜鸟,看这里: Caused by: java.lang.NullPointerException 06-10 22:14:29.940: E/AndroidRuntime(862): at android.app.Activity.findViewById(Activity.java: 22:14:29.940: E/AndroidRuntime(862): at com.swufe.mydorm.Menu.(M...===========================================问:04-03 13:05:23.535: E/AndroidRuntime(409): FATAL EXCEPTION: main 04...答:是NullPointerException空指针错误,检查下下面的点: 1、maintestinfo.xml文件里面添加该activity了么? 2、在activity中应用的控件,有没有用findViewbyId方法和xml中的id对应起来?=========================================== 解决办法 由于SP2各版本所带的DirectX不同,因此常常出现这个问题,早期的SP2带的是DirectX 9.0b,这个版本无法真正升级成9.0C,我用的SP2尽管显示是 9.0C,但一样仍然...=========================================== 你使用的是未破解的Keil软件,最多只允许生成2kB代码。 解决方法: 1、购买正版软件 2、自己去找破解方法===========================================
本文欢迎转载,转载请注明:转载自中国学网: []
用户还关注
可能有帮助下面的这段代码哪里有错吗运行不出来各大神求帮忙解释一下(初学者)_百度知道
下面的这段代码哪里有错吗运行不出来各大神求帮忙解释一下(初学者)
Koo()&&#47;public class gouzaoqi { public static void main(String[] args) {
&#47; }}class Koo{ public Koo(){
class Hoo extends Koo{
public Hoo(){
super(). TODO Auto-generated method stub
new Noo();).println(&quotpackage aa
第三个类继承了第二个类。 第一个是里有main函数作为程序入口代码里说的是3个类。这段代码没有任何作用。第二个类是父类。java
输出结果怎么没有输出结果呢?子类继承父类的方法输出结果不应是“Koo“的 吗?不懂请帮忙解释一下感激了
Hoo类继承了koo类。 因为你的main函数里只是创建了一个noo类对象,但是没有任何操作。所以更不可能有输出。更何况这个noo类也没有定义。不知道是什么来的
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}

我要回帖

更多关于 java管理系统源代码 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信