Jaya Jusco (JJ) Sdn Bhd needs you to develop an application to calculate their customer JJ point’s reward. Define a class named Customer with the following variables declarations:
String CustName;
String CustAddress;
int pointRewards;
Â
a) Â Provide a default constructor and another constructor with three parameters. The constructor with parameters will assign the three values (String CustomerName, String CustomerAddress, int point). Define a public instance method named calculatePoint()to calculate the customer rewards if the point is greater than 300 points. The formula indicates that if the point is greater than 300 points, the system will add up extra 50 points.
b)Define another class named Testing to test the Customer class. Use the Scanner method to get the CustomerName, CustomerAddress and point values from the user. Declare class and create object Customer. Call the calculatePoint( ) method to display the current customer points reward.
import java.util.Scanner;
public class Testing {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
Scanner scan1=new Scanner(System.in);
Scanner scan2=new Scanner(System.in);
System.out.print("Enter your name: ");
String userName=scan.nextLine();
System.out.print("Enter your address: ");
String userAddress=scan1.nextLine();
System.out.print("Enter your points: ");
int userPoints=scan2.nextInt();
Customer customer=new Customer(userName,userAddress,userPoints);
if(userPoints>300){
System.out.println("Your points now: "+customer.calculatePoint());
}
else{
System.out.println("Your points: "+userPoints);
}
}
}
class Customer{
String CustName;
String CustAddress;
int pointRewards;
Customer(){
}
public Customer(String custName, String custAddress, int pointRewards) {
CustName = custName;
CustAddress = custAddress;
this.pointRewards = pointRewards;
}
public int calculatePoint(){
return pointRewards+50;
}
}
Comments
Leave a comment