Question: JAVA Write a method called subtractPoints(), to be added to the Customer class, that subtracts ten points from the points the customer has. Write a
JAVA
Write a method called subtractPoints(), to be added to the Customer class, that subtracts ten points from the points the customer has. Write a program to create a customer object, insert value to its attributes and display the details of the object with an updated value of points.
public class Customer{
private String id;
private String name;
private int points;
public String getId() {
return id;
}
public String getName() {
return name;
}
public int getPoints() {
return points;
}
public String setId(String id) {
id=id;
}
public String setName(String name) {
name=name;
}
public String setPoints(int points) {
points=points;
}
}
public class Encapsulation{
public static void main(String args[]) {
Customer c1 = new Customer();
c1.setName("Sushil");
c1.setId("C-001");
c1.setPoints(120);
System.out.print("Customer Name : " + c1.getName() + " Age : " + c1.getPoints() + "CUstomer ID :" + c1.getId() );
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
