/*
定义类,创建对象,获取键盘输入,对比字符串
*/
import java.util.Scanner;//导包
class Phone
{
String name;
int useTime;
int madeTime;
public void call(int num)
{
System.out.println("正在呼叫 "+num+"...");
System.out.println("好像打不通..");
}
}
class ObjTest1
{
public static void main(String[] args)
{
Phone p1 = new Phone();
Scanner sc = new Scanner(System.in);
System.out.println("你的手机叫什么名字:");
String name = sc.next();//获取键盘输入的字符串
p1.name = name;
System.out.println(name+"什么时候生产的?");
int madeTime = sc.nextInt();
p1.madeTime = madeTime;
System.out.println(name+"用了多久了?");
int useTime = sc.nextInt();
p1.useTime = useTime;
System.out.println("好的,现在"+name+"可以打电话了!拨打什么号码?");
int num = sc.nextInt();
p1.call(num);
System.out.println("呃...好吧,现在看看你的手机信息如何?(y or n)");
String yesOrNo = sc.next();
System.out.println();
//compareTo方法,匹配时返回0,不匹配返回一个负数?
if (yesOrNo.compareTo("y")==0)
{
System.out.println("手机: "+p1.name);
System.out.println("制造时间: "+p1.madeTime+"年");
System.out.println("使用时间: "+p1.useTime+"年");
}
else if (yesOrNo.compareTo("n")==0)
{
System.out.println("嗯..也好");
}
else
{
System.out.println("什么啊?");
}
}
}
大神们看看有什么地方需要改进?大家交流交流~ |
|