求Java 高手赐教啊!!!! 20
ProgrammingAssignemnt11.InthisPA,youfirstneedtostudycarefullytheRentalExample.Thencon...
Programming Assignemnt 1
1. In this PA, you first need to study carefully the Rental Example. Then consider the following requirements:
Northwest Airlines want to develop a new system for the WorldPerks program. In this program, each passenger
has one unique WorldPerks number plus their name. There is three types of status for each passenger who joins the
program: normal, silver, and gold. After travelling with NWA, the system should update the mileage for the
passenger as follows: 1) Normal passenger: update the mileage by the actual travel miles; 2) Silver
passenger: update the mileage by 1.5 * the actual travel miles; 3) Gold passenger: update the mileage by 2 * the
actual travel miles.
2. To implement the above requirements, you need to have the following requirements
Using Eclipse/Java to implement the above program;
Using Inheritance/Polymorphism instead of any conditional statement in your program.
3. How to test your program. The PA1_INPUT file is used to test your program. So your program structure should
be compatible with the test file.
class Testfile {
public static void main(String[] args) {
WorldPerks aProgram = new WorldPerks();
Normal_Customer john = new Normal_Customer("john", 10001); // 10001 is the WorldPerks number
Silver_Customer marry = new Silver_Customer("marry", 10002);
Gold_Customer joe = new Gold_Customer("joe", 10003);
aProgram.addMembers(john);
aProgram.addMembers(marry);
aProgram.addMembers(joe);
john.update_mileage(12000);
marry.update_mileage(23000);
john.update_mileage(2000);
marry.update_mileage(32000);
joe.update_mileage(4000);
joe.update_mileage(21000);
aProgram.printAllCustomerMilege();
// You should print all Cusotmer's mileage infor as the following format:
// john: WorldPerks Number is XXXX and mileage is XXXXXXX;
// marry: WorldPerks Number is XXXXX and mileage is XXXXXXX;
// joe: WorldPerks Number is XXXXX and mileage is XXXXXX;
}
} 展开
1. In this PA, you first need to study carefully the Rental Example. Then consider the following requirements:
Northwest Airlines want to develop a new system for the WorldPerks program. In this program, each passenger
has one unique WorldPerks number plus their name. There is three types of status for each passenger who joins the
program: normal, silver, and gold. After travelling with NWA, the system should update the mileage for the
passenger as follows: 1) Normal passenger: update the mileage by the actual travel miles; 2) Silver
passenger: update the mileage by 1.5 * the actual travel miles; 3) Gold passenger: update the mileage by 2 * the
actual travel miles.
2. To implement the above requirements, you need to have the following requirements
Using Eclipse/Java to implement the above program;
Using Inheritance/Polymorphism instead of any conditional statement in your program.
3. How to test your program. The PA1_INPUT file is used to test your program. So your program structure should
be compatible with the test file.
class Testfile {
public static void main(String[] args) {
WorldPerks aProgram = new WorldPerks();
Normal_Customer john = new Normal_Customer("john", 10001); // 10001 is the WorldPerks number
Silver_Customer marry = new Silver_Customer("marry", 10002);
Gold_Customer joe = new Gold_Customer("joe", 10003);
aProgram.addMembers(john);
aProgram.addMembers(marry);
aProgram.addMembers(joe);
john.update_mileage(12000);
marry.update_mileage(23000);
john.update_mileage(2000);
marry.update_mileage(32000);
joe.update_mileage(4000);
joe.update_mileage(21000);
aProgram.printAllCustomerMilege();
// You should print all Cusotmer's mileage infor as the following format:
// john: WorldPerks Number is XXXX and mileage is XXXXXXX;
// marry: WorldPerks Number is XXXXX and mileage is XXXXXXX;
// joe: WorldPerks Number is XXXXX and mileage is XXXXXX;
}
} 展开
展开全部
public abstract class Customer {
protected String name;
protected int number;
protected double mileage;
public Customer(String name,int num){
this.name=name;
this.number=num;
}
public abstract void update_mileage(double mile);
public void print(){
System.out.println(name+":WorldPerks Number is "+number+" and mileage is "+getMileage());
}
public abstract double getMileage();
}
public class Normal_Customer extends Customer {
public Normal_Customer(String name, int num) {
super(name, num);
}
@Override
public void update_mileage(double mile) {
this.mileage=mile;
}
@Override
public double getMileage() {
return mileage;
}
}
public class Silver_Customer extends Customer {
public Silver_Customer(String name, int num) {
super(name, num);
}
@Override
public void update_mileage(double mile) {
this.mileage=mile;
}
@Override
public double getMileage() {
return 1.5*mileage;
}
}
public class Gold_Customer extends Customer {
public Gold_Customer(String name, int num) {
super(name, num);
}
@Override
public void update_mileage(double mile) {
this.mileage=mile;
}
@Override
public double getMileage() {
return 2*mileage;
}
}
import java.util.ArrayList;
public class WorldPerks {
ArrayList<Customer> lists;
public WorldPerks(){
lists=new ArrayList<Customer>();
}
public void addMembers(Customer customer){
lists.add(customer);
}
public void printAllCustomerMilege(){
int len=lists.size();
for(int i=0;i<len;i++)
lists.get(i).print();
}
}
protected String name;
protected int number;
protected double mileage;
public Customer(String name,int num){
this.name=name;
this.number=num;
}
public abstract void update_mileage(double mile);
public void print(){
System.out.println(name+":WorldPerks Number is "+number+" and mileage is "+getMileage());
}
public abstract double getMileage();
}
public class Normal_Customer extends Customer {
public Normal_Customer(String name, int num) {
super(name, num);
}
@Override
public void update_mileage(double mile) {
this.mileage=mile;
}
@Override
public double getMileage() {
return mileage;
}
}
public class Silver_Customer extends Customer {
public Silver_Customer(String name, int num) {
super(name, num);
}
@Override
public void update_mileage(double mile) {
this.mileage=mile;
}
@Override
public double getMileage() {
return 1.5*mileage;
}
}
public class Gold_Customer extends Customer {
public Gold_Customer(String name, int num) {
super(name, num);
}
@Override
public void update_mileage(double mile) {
this.mileage=mile;
}
@Override
public double getMileage() {
return 2*mileage;
}
}
import java.util.ArrayList;
public class WorldPerks {
ArrayList<Customer> lists;
public WorldPerks(){
lists=new ArrayList<Customer>();
}
public void addMembers(Customer customer){
lists.add(customer);
}
public void printAllCustomerMilege(){
int len=lists.size();
for(int i=0;i<len;i++)
lists.get(i).print();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询