Answer to Question #235659 in Java | JSP | JSF for Siya

Question #235659

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).


1
Expert's answer
2021-09-10T09:03:51-0400
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;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS