Create a class named Customer that will determine the monthly repayment amount due by a customer for a product bought on credit. The class has five fields: customer name, contact number, product price, number of months and the monthly repayment amount. Write get and set methods for each field, except for the monthly repayment amount field. The set methods must prompt the user to enter the values for the following fields: customer name, contact number, product price and number of months. This class also needs a method to calculate the monthly repayment amount (product price divided by the number of months).
import java.util.Scanner;
public class Customer {
private String customerName;
private int contactNumber;
private double productPrice;
private int numberOfMonths;
private double monthlyRepayment;
public String getCustomerName() {
return customerName;
}
public void setCustomerName() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the customer name:");
customerName = in.nextLine();
}
public int getContactNumber() {
return contactNumber;
}
public void setContactNumber() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the customer number:");
contactNumber = Integer.parseInt(in.nextLine());
}
public double getProductPrice() {
return productPrice;
}
public void setProductPrice() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the product price:");
productPrice = Double.parseDouble(in.nextLine());
}
public int getNumberOfMonths() {
return numberOfMonths;
}
public void setNumberOfMonths() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of months:");
numberOfMonths = Integer.parseInt(in.nextLine());
}
public void calculateMonthlyRepayment() {
monthlyRepayment = productPrice / numberOfMonths;
}
}
Comments
Leave a comment