Question

In: Computer Science

N/B: THE PROGRAMME SHOULD BE WRITTEN IN JAVA LANGUAGE CS 202 Part 1. Create a class...


N/B: THE PROGRAMME SHOULD BE WRITTEN IN JAVA LANGUAGE
CS 202
Part 1.
   Create a class called Loan.  An instance of the class can be used to calculate
   information about a bank loan.  
   
   The class should have the following methods:
   
   a. A constructor  that is passed the amount being borrowed, the annual interest
      rate and the number of years for repayment.
      
   b. A default constructor that initializes the amount being borrowed, the annual 
      interest rate and the number of years for repayment to 0.
      
   c. "get" methods (accessors) for the loan amount, the annual interest rate and the 
       number of years for repayment.
   
   d. "set" methods (mutators) for the loan amount, the annual interest rate and the 
      number of years for repayment.
   
   e. A method that calculates and returns the amount of the monthly payment for
      the loan.
      The monthly payment on a loan can be calculated using the following formula:


                             loanAmount * R
      monthly payment =     --------------------
                                        -N
                           1 -  (1 + R )
                        
      R = monthly rate of interest for the loan
      N = number of months to repay the loan
      
   
   
   f. A method that returns the sum of all payments needed to repay the loan.
   
   g. A method that returns the sum of all interest paid on the loan.
   
   
Part 2.   
   Write an application that tests the Loan class.  The program should allow the user to
   create a loan, enter information about the loan and make changes to the amount of
   the loan, the interest rate, and the number of years to repay the loan.
   

Solutions

Expert Solution

Code to copy along with screenshots of code and output are provided.
Please refer to screenshots to understand the indentation of code.
If you have any doubts or issues. Feel free to ask in comments
Please give this answer a like, or upvote. This will be very helpful for me.
================================================================

Screenshots of "Loan.java" :

Screenshots of "LoanTest.java"

Screenshots of Output :

Code to copy("Loan.java"):

public class Loan {
  
   // member variables
   double amount;
   double annualInterestRate;
   double years;
  
   // default constructor
   Loan()
   {
       // setting all value to 0
       this.amount = 0;
       this.annualInterestRate = 0;
       this.years = 0;
   }

   // constructor that takes 3 arguments
   Loan(double amount, double annualInterestRate,double years)
   {
       // setting values accordingly
       this.amount = amount;
       this.annualInterestRate = annualInterestRate;
       this.years = years;
   }
  
   // get method to return amount
   double getAmount()
   {
       return this.amount;
   }
  
   // get method to return Annual Interest Rate
   double getInterestRate()
   {
       return this.annualInterestRate;
   }
  
   // get method to return number of years
double getYears()
{
   return this.years;
}
  
// set method for setting the amount
void setAmount(double loanAmount)
{
   this.amount = loanAmount;
}
  
//set method for setting Annual Interest Rate
void setInterestRate(double interestRate)
{
   this.annualInterestRate = interestRate;
  
}
  
//set method to set number of years
void setYears(double years)
{
   this.years = years;
  
}
  
// method to return monthly payment
double monthlyPayment()
{
   // calculating monthly interest rate
   double r = (this.annualInterestRate)/12;
  
   // calculating number of months
   double n = 12*this.years;
  
   // amount
   double a = this.amount;
  
   // formula for calculating emi
   double emi = (a * r/100 * Math.pow((1+(r/100)),n)) / (Math.pow((1+(r/100)),n)-1);
  
   // returning emi amount
   return emi;
  
}
  
// function to return sum of all payments needed to repay the loan
double totalPayment()
{
   // calculating total payment
   double totalPay = monthlyPayment()*12*10;

   return totalPay;
}
  
// function to return amount to total Interest to be paid
double totalInterestPayment()
{
   // calculating total Interest
   double totalInterest = totalPayment() - this.amount;
  
   return totalInterest;
}


}


Code to copy("LoanTest.java"):

public class LoanTest {

  
   public static void main(String args[])
   {
   // creating instance of loan
       Loan loan = new Loan();
  
  
       // declaring variables
       double loanAmount = 700000;
   double years = 10;
   double interestRate = 8.5;
  
   // setting value of loan Amount
   loan.setAmount(loanAmount);
  
   // setting value of number of years
   loan.setYears(years);
  
   //setting value of annual Interest rate
   loan.setInterestRate(interestRate);
  
   // displaying loan Amount
   System.out.println("Loan Amount: "+loanAmount);
  
   // displaying no of years
   System.out.println("Years: "+years);
  
   // displaying Annual Interest Rate
   System.out.println("Annual Interest Rate: "+interestRate);
  
   // displaying EMI
   System.out.println("\nEvery Month Payment = "+String.format(" %.2f",loan.monthlyPayment()));
  
   // displaying total amount to be paid
   System.out.println("Total Amount to be paid overall = "+String.format(" %.2f",loan.totalPayment()));
  
   // displaying total Interest to be paid
   System.out.println("Total Interest to be paid = "+String.format(" %.2f",loan.totalInterestPayment()));
   }
  
  
  
}

=============================XXX================



Related Solutions

JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign4Test.java. Copy your code from Assignment 3 into the Student.java and StudentList.java. Assign4Test.java should contain the main method. In Student.java, add a new private variable of type Integer called graduationYear. In Student.java, create a new public setter method setGraduationYear to set the graduationYear. The method will have one parameter of type Integer. The method will set...
Programming language to be used: Java Exercises Part 1) The Dog Class In the first part...
Programming language to be used: Java Exercises Part 1) The Dog Class In the first part of the lab, we are writing a class to represent a Dog. It should not have a main method. Dog needs fields for price (to purchase the dog), breed, name, and age. Use appropriate data types The class should have the following two kinds of Constructors: Constructor 1: Write a constructor that accepts a value for each of the fields Constructor 2: Write a...
This program should be written in Java language. Given the uncertainty surrounding the outbreak of the...
This program should be written in Java language. Given the uncertainty surrounding the outbreak of the Coronavirus disease (COVID-19) pandemic, our federal government has to work tirelessly to ensure the distribution of needed resources such as medical essentials, water, food supply among the states, townships, and counties in the time of crisis. You are a software engineer from the Right Resource, a company that delivers logistic solutions to local and state entities (schools, institutions, government offices, etc). You are working...
This program is written in Java and should be modularized in methods in one class. This...
This program is written in Java and should be modularized in methods in one class. This program will calculate the Gross Earnings, FICA tax (Medicare and Social Security taxes), Federal Tax Withheld, and Net Amount of the payroll check for each employee of a company. The output must contain numbers with 2 decimal places. The user input must be validated – if incorrect data is entered, send an error message to the user. INPUT The application must be able to...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
Part A Java netbeans ☑ Create a project and in it a class with a main....
Part A Java netbeans ☑ Create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class , after the package statement, paste import java.util.Scanner; As the first line inside your main method, paste Scanner scan = new Scanner(System.in); Remember when you are getting a value from the user, first print a request, then use the Scanner to read the right type...
Program should be written in Java b) The computer program should prompt the user (You are...
Program should be written in Java b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT