HPVISACARD.JAVA:
class HPVISACard extends VISACard{
public HPVISACard(String type, double reward, double amount) {
super(type, reward, amount);
// TODO Auto-generated constructor stub
}
public HPVISACard() {
// TODO Auto-generated constructor stub
}
public Double computeRewardPoints(String type, Double amount){
//fill code here
if(type.equalsIgnoreCase("Fuel")) {
double reward2= 0.01*amount+10;
return reward2;
}else {
super.computeRewardPoints(type, amount);
double reward3=001*amount;
return reward3;
}
}
}
class HPVISACard extends VISACard{ public HPVISACard(String type, double reward, double amount) { super(type, reward, amount); // TODO Auto-generated constructor stub } public HPVISACard() { // TODO Auto-generated constructor stub } public Double computeRewardPoints(String type, Double amount){ //fill code here if(type.equalsIgnoreCase("Fuel")) { double reward2= 0.01*amount+10; return reward2; }else { super.computeRewardPoints(type, amount); double reward3=001*amount; return reward3; } } }
VISACARD.JAVA:
public class VISACard {
String type;
double amount;
double reward;
public VISACard(){
}
public VISACard(String type, double reward, double amount) {
super();
this.type = type;
this.reward = reward;
this.amount = amount;
}
public Double computeRewardPoints(String type, Double amount){
this.amount=amount;
this.reward=reward;
reward=0.01*amount;
return reward;
}
}
public class VISACard { String type; double amount; double reward; public VISACard(){ } public VISACard(String type, double reward, double amount) { super(); this.type = type; this.reward = reward; this.amount = amount; } public Double computeRewardPoints(String type, Double amount){ this.amount=amount; this.reward=reward; reward=0.01*amount; return reward; } }
MAIN.JAVA:
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in).useDelimiter("\n");
VISACard visaCard;
String contd;
do{
System.out.println("Enter the transaction detail");
String input=sc.next();
String[] inputs=input.split(",");
if(inputs[2].equals("VISA card")){
visaCard=new VISACard();
double reward=visaCard.computeRewardPoints(inputs[0],Double.parseDouble(inputs[1]));
System.out.println("Total reward points earned in this transaction is "+String.format("%.2f",reward));
}
else if(inputs[2].equals("HPVISA card")){
visaCard=new HPVISACard();
double reward=visaCard.computeRewardPoints(inputs[0],Double.parseDouble(inputs[1]));
System.out.println("Total reward points earned in this transaction is "+String.format("%.2f",reward));
}
else{
System.out.println("Invalid data");
}
System.out.println("Do you want to continue?(Yes/No)");
contd=sc.next();
}
while(contd.equalsIgnoreCase("Yes"));
}
}
import java.io.*; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in).useDelimiter("\n"); VISACard visaCard; String contd; do{ System.out.println("Enter the transaction detail"); String input=sc.next(); String[] inputs=input.split(","); if(inputs[2].equals("VISA card")){ visaCard=new VISACard(); double reward=visaCard.computeRewardPoints(inputs[0],Double.parseDouble(inputs[1])); System.out.println("Total reward points earned in this transaction is "+String.format("%.2f",reward)); } else if(inputs[2].equals("HPVISA card")){ visaCard=new HPVISACard(); double reward=visaCard.computeRewardPoints(inputs[0],Double.parseDouble(inputs[1])); System.out.println("Total reward points earned in this transaction is "+String.format("%.2f",reward)); } else{ System.out.println("Invalid data"); } System.out.println("Do you want to continue?(Yes/No)"); contd=sc.next(); } while(contd.equalsIgnoreCase("Yes")); } }