I'm a first-year student and I'm really struggling here. This is one of the questions that I have to do for my Assignment (I am allowed to use StackOverflow for guidance).
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 a number of months
.
This class also needs a method to calculate the monthly repayment amount (product price divided by the number of months).
Add a subclass named Finance_Period
that will determine if a customer will pay interest or not.
If the number of months to pay for the product is greater than three, the customer will pay 25% interest, or else no interest applies.
The maximum number of months to pay for the product is 12.
Override the calculate_repayment()
method by determining if the customer will pay interest or not and calculate the monthly repayment amount.
Create a class called Customer_Finance
that contains the logic to test the two classes.
Prompt the user for data for the first object where no interest applies and display the results; then prompt the user for data where interest is applicable and displays the results.
I'm struggling to call amtRepay
into my main without using getters
and setters
.
I'm not even sure if I understand the question correctly, any guidance or advice would be greatly appreciated.
Also, I have another class called Finace_Period
, there is nothing there yet, I'm not 100% sure of what I'm doing yet.
This is my main class, where I want to display amtRepay
.
package main;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
//Variables
String name;
int cNumber, months;
double price;
//Input
name = JOptionPane.showInputDialog(null, "Please enter the customer's name:");
cNumber = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the customer's contact number:"));
price = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter the price of the product:"));
months = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the number of repayment months:"));
Customer c = new Customer(name, cNumber, months, price);
JOptionPane.showMessageDialog(null, c.calcaAmtRepay());
}
}
and this is my secondary class, where amtRepay
is calculated.
package Main;
public class Customer extends Finance_Period {
//Atributes
private String name;
private int cNumber, months;
private double price, amtRepay;
//Constructors
public Customer (String name, int cNumber, int months, double price) {
this.name = name;
this.cNumber = cNumber;
this.months = months;
this.price = price;
}
//Getters
public String getName() {
return name;
}
public int getcNumber() {
return cNumber;
}
public int getMonths() {
return months;
}
public double getPrice() {
return price;
}
//Setter
public void setName(String name) {
this.name = name;
}
public void setcNumber(int cNumber) {
this.cNumber = cNumber;
}
public void setMonths(int months) {
this.months = months;
}
public void setPrice(double price) {
this.price = price;
}
//Calculation of monthly repayments
public double calcAmtRepay () {
amtRepay = price / months;
return price / months;
}
}
Thanks.