| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 802 人关注过本帖
标题:一个菜鸟的问题。
只看楼主 加入收藏
tobyliying
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-4-16
收藏
 问题点数:0 回复次数:10 
一个菜鸟的问题。

import java.io.*;
public class CCar
{
public class car1 // 基类
{

car1(String tap)
{
if(tap=="big")
System.out.println("this call number is:45656798");
if(tap=="mid")
System.out.println("this call number is:5667800");
if(tap=="lit")
System.out.println("this call number is:23454665");
}
}

public class bigcar extends car1 // 大车
{
bigcar()
{ car1 client=new car1("big");
System.out.println("rent="+300);

}
}

public class midcar extends car1 // 中车
{
midcar()
{ car1 client=new car1("mid");
System.out.println("rent="+400);

}
}

public class litcar extends car1 // 小车
{
litcar()
{ car1("lit");
System.out.println("rent="+500);

}
}

public static void main(String[]args) throws IOException // 主函数
{

BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String a;
a=buf.readLine();
if(a=="big")
bigcar();
if(a=="mid")
midcar();
if(a=="lit")
litcar();
}
}
  我想用继承的方法 来输出  大中小汽车的价格和  电话..
 请各位帮我改下OK?

搜索更多相关主题的帖子: public number import 
2007-05-25 00:30
tobyliying
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-4-16
收藏
得分:0 

import java.io.*;
import java.lang.*;
public class CCar
{
public class car1 // 基类
{
String tap;

car1(String tap)
{
if(this.tap=="big")
System.out.println("this call number is:45656798");
if(this.tap=="mid")
System.out.println("this call number is:5667800");
if(this.tap=="lit")
System.out.println("this call number is:23454665");
}
}

public class bigcar extends car1 // 大车
{
bigcar(String tap)
{ super(tap);
System.out.println("rent="+300);

}
}

public class midcar extends car1 // 中车
{
midcar(String tap)
{ super(tap);
System.out.println("rent="+400);

}
}

public class litcar extends car1 // 小车
{
litcar(String tap)
{ super(tap);
System.out.println("rent="+500);

}
}

public static void main(String[] args) throws IOException // 主函数
{
car1 client;
bigcar client1;
midcar client2;
litcar clietn3;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String a;
a=buf.readLine();
if(a=="big")
client1=new bigcar(a);
if(a=="mid")
client2=new midcar(a);
if(a=="lit")
client3=new litcar(a);
}


我改了下..但是还是抱错.. 各位看一下呀。

2007-05-25 01:21
tobyliying
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-4-16
收藏
得分:0 
没有人吗..  帮我看看呀。.
2007-05-25 01:23
changyawei
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2005-11-3
收藏
得分:0 
回复:(tobyliying)一个菜鸟的问题。
if(tap=="big")
System.out.println("this call number is:45656798");
if(tap=="mid")
System.out.println("this call number is:5667800");
if(tap=="lit")
System.out.println("this call number is:23454665");
你的字符串比较有问题吧.\
不能用== 要用equals()
2007-05-25 16:54
prayer
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-5-13
收藏
得分:0 
回复:(tobyliying)import java.io.*;import java.l...
我现在不明白你是什么意思??是要根据命令行参数,决定输出的是什么类型的卡车,然后输出还有租金

2007-05-25 17:25
tobyliying
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-4-16
收藏
得分:0 
我是要用流的方法输入 参数 在来决定车的类型  在输出租金
2007-05-28 10:00
fkl888
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-2-12
收藏
得分:0 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class car1 // 基类
{


car1(String tap)
{
if(tap.equals("big"))
System.out.println("this call number is:45656798");
if(tap.equals("mid"))
System.out.println("this call number is:5667800");
if(tap.equals("lit"))
System.out.println("this call number is:23454665");
}
}

class bigcar extends car1 // 大车
{
bigcar(String tap)
{ super(tap);
System.out.println("rent="+300);

}
}

class midcar extends car1 // 中车
{
midcar(String tap)
{ super(tap);
System.out.println("rent="+400);

}
}

class litcar extends car1 // 小车
{
litcar(String tap)
{ super(tap);
System.out.println("rent="+500);

}
}
public class CCar
{
public static void main(String[] args) throws IOException // 主函数
{

bigcar client1;
midcar client2;
litcar clietn3;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String a;
a=buf.readLine();
System.out.println(a);
if(a.equals("big"))
client1=new bigcar(a);
if(a.equals("mid"))
client2=new midcar(a);
if(a.equals("lit"))
clietn3=new litcar(a);

}
}
试试看~~~

2007-05-28 11:42
prayer
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-5-13
收藏
得分:0 
回复:(fkl888)import java.io.BufferedReader;impo...
请问你该了什么地方!!本人眼拙没找到

2007-05-28 18:05
fkl888
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-2-12
收藏
得分:0 

没改什么 就 == 改位 equals
把public类CCar放在最下面,其他类的public修饰都删了

2007-05-28 19:27
午夜屠猪男
Rank: 4
等 级:业余侠客
威 望:2
帖 子:194
专家分:259
注 册:2007-1-3
收藏
得分:0 
    用equals来比较
 ==是比较他们的地址
  

2007-05-28 22:05
快速回复:一个菜鸟的问题。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013019 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved