用接口回调的题目 景区 根据收费制度不同 儿童 多少钱学生 多少钱军人 多少钱成年人 多少钱来写一个接口或者面向抽象类的程序谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public interface Price { /** * 根据收费制度门票价格不同。 * @param div 人员种类(儿童:1 学生:2 军人:3 成年人:4) * @return 门票价格 */ public int getPrice(String div);} import java.util.HashMap;public class Test_9 { /** * 人类。只是起到标识作用。 */ interface Human{ } /** * 儿童 */ class Children implements Human{ } /** * 学生 */ static class Student implements Human{ } /** * 军人 */ class Soldier implements Human{ } /** * 成年人 */ class Adult implements Human{ } /** * 收费策略 */ interface Charging{ /** * 费用(单位:分) * @return 获得当前费用 */ int getFeeValue(); } /** * 儿童收费策略 */ static class ChildrenCharging implements Charging{ public int getFeeValue() { return 2000; } } /** * 学生收费策略 */ static class StudentCharging implements Charging{ public int getFeeValue() { return 600; } } /** * 军人收费策略 */ static class SoldierCharging implements Charging{ public int getFeeValue() { return 800; } } /** * 成年人收费策略 */ static class AdultCharging implements Charging{ public int getFeeValue() { return 1000; } } /** * 收费制度 */ static class TheChargingSystem{ private HashMap<Class<? extends Human>, Charging> charging = new HashMap<Class<? extends Human>, Charging>(); public Charging getCharging(Human human){ return charging.get(human.getClass()); } public Charging getCharging(Class<Human> type){ return charging.get(type); } public void setCharging(Class<? extends Human> humanType,Charging charging){ this.charging.put(humanType,charging); } } /** * 用例 */ public static void main(String[] args) { //创建收费制度对象 TheChargingSystem tcs = new TheChargingSystem(); //配置相关的收费制度 tcs.setCharging(Children.class, new ChildrenCharging()); tcs.setCharging(Student.class, new StudentCharging()); tcs.setCharging(Soldier.class, new SoldierCharging()); tcs.setCharging(Adult.class, new AdultCharging()); //使用场景,使用收费制度对象,得到对应的收费值 Student stdu = new Student(); Charging charging = tcs.getCharging(stdu); System.out.println(charging.getFeeValue()); }} 我声明了一个TextField,怎么样才能够在其中加入换行呢?如果是setText()那么参数是什么呢? 关于null的问题 帮忙找一下错误 老婆叫我写一个算法,竟然想了一晚上没想出来,感觉还是有难度 有没有适合有编程经验的人快速掌握java的教程资料一类的 写了个Applet,大家来看看 getValue() 200分求教,httpurlconnection post数据的问题,附源码 大量开发图书资料下载 为什么对的代码报错呢?! 关于两个类绘制图片的问题 为什么要写interface
public interface Price { /**
* 根据收费制度门票价格不同。
* @param div 人员种类(儿童:1 学生:2 军人:3 成年人:4)
* @return 门票价格
*/
public int getPrice(String div);
}
public class Test_9 { /**
* 人类。只是起到标识作用。
*/
interface Human{ }
/**
* 儿童
*/
class Children implements Human{
}
/**
* 学生
*/
static class Student implements Human{
}
/**
* 军人
*/
class Soldier implements Human{
}
/**
* 成年人
*/
class Adult implements Human{
}
/**
* 收费策略
*/
interface Charging{
/**
* 费用(单位:分)
* @return 获得当前费用
*/
int getFeeValue();
}
/**
* 儿童收费策略
*/
static class ChildrenCharging implements Charging{
public int getFeeValue() {
return 2000;
}
}
/**
* 学生收费策略
*/
static class StudentCharging implements Charging{
public int getFeeValue() {
return 600;
}
}
/**
* 军人收费策略
*/
static class SoldierCharging implements Charging{
public int getFeeValue() {
return 800;
}
}
/**
* 成年人收费策略
*/
static class AdultCharging implements Charging{
public int getFeeValue() {
return 1000;
}
}
/**
* 收费制度
*/
static class TheChargingSystem{
private HashMap<Class<? extends Human>, Charging> charging = new HashMap<Class<? extends Human>, Charging>();
public Charging getCharging(Human human){
return charging.get(human.getClass());
}
public Charging getCharging(Class<Human> type){
return charging.get(type);
}
public void setCharging(Class<? extends Human> humanType,Charging charging){
this.charging.put(humanType,charging);
}
}
/**
* 用例
*/
public static void main(String[] args) {
//创建收费制度对象
TheChargingSystem tcs = new TheChargingSystem();
//配置相关的收费制度
tcs.setCharging(Children.class, new ChildrenCharging());
tcs.setCharging(Student.class, new StudentCharging());
tcs.setCharging(Soldier.class, new SoldierCharging());
tcs.setCharging(Adult.class, new AdultCharging());
//使用场景,使用收费制度对象,得到对应的收费值
Student stdu = new Student();
Charging charging = tcs.getCharging(stdu);
System.out.println(charging.getFeeValue());
}}