Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package com.codewithrong; import java.text.NumberFormat; import java.util.Scanner; public class Main { final static byte MONTHS_IN_YEAR = 12; final static byte PERCENT = 100; public static void

image text in transcribed

package com.codewithrong; import java.text.NumberFormat; import java.util.Scanner; public class Main { final static byte MONTHS_IN_YEAR = 12; final static byte PERCENT = 100; public static void main(String[] args) { int principal = (int) readNumber("Principal: ", 1000, 1_000_000); float annualInterest = (float) readNumber("Annual Interest Rate: ", 1, 30); byte years = (byte) readNumber("Period (Years): ", 1, 30); printMortgage(principal, annualInterest, years); printPaymentSchedule(principal, annualInterest, years); } private static void printMortgage(int principal, float annualInterest, byte years) { double mortgage = calculateMortgage(principal, annualInterest, years); String mortgageFormatted = NumberFormat.getCurrencyInstance().format(mortgage); System.out.println(); System.out.println("MORTGAGE"); System.out.println("--------"); System.out.println("Monthly Payments: " + mortgageFormatted); } private static void printPaymentSchedule(int principal, float annualInterest, byte years) { System.out.println(); System.out.println("PAYMENT SCHEDULE"); System.out.println("----------------"); for (short month = 1; month = min && value   Homework assignment \# This assignment includes main.java file. First open the file and run the program in IntelliJ. This code is written in procedural programming. And we know the problems of this procedural code: Big classes with several unrelated methods focusing on different concerns and responsibilities. These methods often have several parameters. You often see the same group of parameters repeated across these methods. All you see is procedures calling each other passing arguments around. For your job, you need to refactor this code by applying object-oriented programming techniques (encapsulation, abstraction), for example: extract these repetitive parameters and declare them as fields in our classes. Our classes will then encapsulate both the data and the operations on the data (methods). As a result, our methods will have fewer parameters and our code will be cleaner and more reusable. To finish this assignment, you need to follow the following two steps: Step1: run the code I give to you in IntelliJ, try to understand the code. This is a good opportunity to learn Java. Once you understand the code, you can get started to think about what classes need to be extracted. Step2: when you finished the first step, you can get started to build the classes and make your code object-oriented

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions