public class chengfa {
private int shu;
private int shu2;
public void getShu(int shu)
{
this.shu=shu;
}
public void getShu2(int shu)
{
this.shu2=shu;
}
public void jisuan()
{
System.out.println("How much is"+" "+shu+" "+"times"+" "+shu2);
}
public int panduan(int jieguo)
{
if (shu*shu2==jieguo)
{
System.out.println("Very good");
System.out.println("下一题");
}
else {
System.out.println("No.Please try again");
cuowu();
}
return jieguo;
}
public void cuowu()
{
int zaiyici=shu*shu2;
Scanner scanner = new Scanner(System.in);
for (int i =0;i>-1;i++)
{
System.out.println("重复该题");
System.out.println("How much is"+shu+" "+"times"+" "+shu2);
int jieguo2=scanner.nextInt();
if (jieguo2==zaiyici){
System.out.println("Very good");
break;
}
}
}
}
public class main2 {
public static void main(String[] args) {
chengfa cheng =new chengfa();
for (int i = 0;i>-1;i++)
{
int shu =(int)(Math.random()*10);
cheng.getShu(shu);
int shu2 = (int) (Math.random() * 10);
cheng.getShu2(shu2);
cheng.jisuan();
Scanner scanner = new Scanner(System.in);
System.out.println("输入答案");
int jieguo = scanner.nextInt();
cheng.panduan(jieguo);
}
}
}
public abstract class MotoVehicle {
private String no;//车牌号
private String brand;//品牌
abstract int calRent(int days);//计算租金
public MotoVehicle()
{
}
public MotoVehicle(String no, String brand)
{
this.no = no;
this.brand = brand;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
}
public class Car extends MotoVehicle{
public Car(String no, String brand)
{
super(no,brand);
}
@Override
int calRent(int days) {
if(getBrand().equals("宝马"))
{
return 500 * days;
}
else
{
return 600 * days;
}
}
}
public class Bus extends MotoVehicle {
private int seatCount;
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
public Bus(String no, String brand, int seatCount)
{
super(no,brand);
this.seatCount = seatCount;
}
@Override
int calRent(int days) {
if (seatCount<=16)
{
return 800*days;
}
else {
return 1500*days;
}
}
}
public class TestRent {
public static void main(String[] args) {
System.out.println("欢迎");
System.out.println("请输入天数");
Scanner scanner = new Scanner(System.in);
int days = scanner.nextInt();
System.out.println("请输入汽车类型1.轿车,2.客车");
int type = scanner.nextInt();
if(type == 1)
{
System.out.println("输入品牌");
String brand = scanner.next();
Car car = new Car("辽N12345",brand);
int money = car.calRent(days);
System.out.println("租金为"+money);
}
else
{
System.out.println("输入座位数");
int seatCount=scanner.nextInt();
Bus bus = new Bus("liaoN3412","金龙",seatCount);
int money = bus.calRent(days);
System.out.println("租金为"+money);
}
}
}
网友评论