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?
----------------解决方案--------------------------------------------------------
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);
}
}
我改了下..但是还是抱错.. 各位看一下呀。
----------------解决方案--------------------------------------------------------
没有人吗.. 帮我看看呀。.
----------------解决方案--------------------------------------------------------
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()
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
我是要用流的方法输入 参数 在来决定车的类型 在输出租金
----------------解决方案--------------------------------------------------------
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);
}
}
试试看~~~
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
没改什么 就 == 改位 equals
把public类CCar放在最下面,其他类的public修饰都删了
----------------解决方案--------------------------------------------------------
用equals来比较
==是比较他们的地址
----------------解决方案--------------------------------------------------------