SlideShare a Scribd company logo
1 of 3
Download to read offline
Change to oop format
import java.util.Scanner;
import java.io.*;
import java.text.DecimalFormat;
public class Amortization {
/* call values in, set balance and principle. set month to increment until reaching number
provided. use t to space out result well.
Use PritWriter output instead of System.output to make the notepad file.*/
public static void createReport(String filename, double loan, double interestRate, int years)
throws IOException {
PrintWriter output = new PrintWriter(new FileWriter(filename));
double monthlyPayment = calcPayment(loan, interestRate, years);
int numberOfPayments = getNumberOfPayments(years);
double balance = loan;
output.println("{Monthly Payment}: " + monthlyPayment);
output.println("{Month} t {Interest} t {Principal} t {Balance}");
for (int month = 1; month <= numberOfPayments; month++) {
double interest = balance * (interestRate / 12);
double principal = monthlyPayment - interest;
balance -= principal;
output.printf("%d t t %.2f t t %.2f t t %.2f n", month, interest, principal, balance);
}
output.close();
}
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.##");
do {
/* Data members */
double loan;
int years;
double interestRate;
/* Get amount, interest rate, and years from the user */
System.out.println("Enter the loan amount: ");
loan = keyboard.nextDouble();
System.out.println("Enter the annual interest rate: ");
interestRate = keyboard.nextDouble() / 100.0;
System.out.println("Enter the years of the loan: ");
years = keyboard.nextInt();
double payment = calcPayment(loan, interestRate, years);
if (payment < 0) {
System.out.println("Invalid input values.");
} else {
System.out.println("Monthly Payment: " + df.format(payment));
int numberOfPayments = getNumberOfPayments(years);
System.out.println("Total Number of Payments: " + numberOfPayments);
try {
createReport("LoanAmortization.txt", loan, interestRate, years);
System.out.println("Report created successfully.");
} catch (IOException e)
{
System.out.println("Error creating report: " + e.getMessage());
}
}
System.out.println("Would you like to run another report? Enter Y for yes or N for no: ");
} while (keyboard.next().equalsIgnoreCase("Y"));
keyboard.close();
}
public static double calcPayment(double loan, double interestRate, int years) {
double term = Math.pow(1 + (interestRate / 12), years * 12);
double payment = (loan * (interestRate / 12) * term) / (term - 1);
return payment;
}
public static int getNumberOfPayments(int years) {
return years * 12; // Assuming monthly payments for the given number of years
}
public static void createReport(String filename) throws IOException {
// Sample implementation to save data to a file
PrintWriter out = new PrintWriter(new FileWriter(filename, true));
out.println("Sample Data");
out.close();
}
}

More Related Content

Similar to Change to oop formatimport java.util.Scanner;import java.io.;.pdf

Write a banking program that simulates the operation of your local ba.docx
 Write a banking program that simulates the operation of your local ba.docx Write a banking program that simulates the operation of your local ba.docx
Write a banking program that simulates the operation of your local ba.docxajoy21
 
Write a program that uses nested loops to collect data and calculate .docx
 Write a program that uses nested loops to collect data and calculate .docx Write a program that uses nested loops to collect data and calculate .docx
Write a program that uses nested loops to collect data and calculate .docxajoy21
 
Please tell me why I get this error in my code I have the screen sh.pdf
Please tell me why I get this error in my code I have the screen sh.pdfPlease tell me why I get this error in my code I have the screen sh.pdf
Please tell me why I get this error in my code I have the screen sh.pdfamarndsons
 
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdfC++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdfJUSTSTYLISH3B2MOHALI
 
My code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdfMy code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdfadianantsolutions
 
C++ coding for Banking System program
C++ coding for Banking System programC++ coding for Banking System program
C++ coding for Banking System programHarsh Solanki
 
Interest.javaimport java.util.Scanner; public class Interest.pdf
 Interest.javaimport java.util.Scanner; public class Interest.pdf Interest.javaimport java.util.Scanner; public class Interest.pdf
Interest.javaimport java.util.Scanner; public class Interest.pdfaradhana9856
 
Java Language.....pdf
Java Language.....pdfJava Language.....pdf
Java Language.....pdfbadshetoms
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfpnaran46
 

Similar to Change to oop formatimport java.util.Scanner;import java.io.;.pdf (10)

Write a banking program that simulates the operation of your local ba.docx
 Write a banking program that simulates the operation of your local ba.docx Write a banking program that simulates the operation of your local ba.docx
Write a banking program that simulates the operation of your local ba.docx
 
Write a program that uses nested loops to collect data and calculate .docx
 Write a program that uses nested loops to collect data and calculate .docx Write a program that uses nested loops to collect data and calculate .docx
Write a program that uses nested loops to collect data and calculate .docx
 
Please tell me why I get this error in my code I have the screen sh.pdf
Please tell me why I get this error in my code I have the screen sh.pdfPlease tell me why I get this error in my code I have the screen sh.pdf
Please tell me why I get this error in my code I have the screen sh.pdf
 
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdfC++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
 
My code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdfMy code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdf
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
C++ coding for Banking System program
C++ coding for Banking System programC++ coding for Banking System program
C++ coding for Banking System program
 
Interest.javaimport java.util.Scanner; public class Interest.pdf
 Interest.javaimport java.util.Scanner; public class Interest.pdf Interest.javaimport java.util.Scanner; public class Interest.pdf
Interest.javaimport java.util.Scanner; public class Interest.pdf
 
Java Language.....pdf
Java Language.....pdfJava Language.....pdf
Java Language.....pdf
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdf
 

More from MAYANKBANSAL1981

Business management 1. True or False Diversification is when compa.pdf
Business management  1. True or False Diversification is when compa.pdfBusiness management  1. True or False Diversification is when compa.pdf
Business management 1. True or False Diversification is when compa.pdfMAYANKBANSAL1981
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdfMAYANKBANSAL1981
 
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdfCase Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdfMAYANKBANSAL1981
 
Can some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdfCan some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdfMAYANKBANSAL1981
 
Banks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdfBanks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdfMAYANKBANSAL1981
 
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdfASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdfMAYANKBANSAL1981
 
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdfA. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdfMAYANKBANSAL1981
 
About your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdfAbout your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdfMAYANKBANSAL1981
 
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdfAbout your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdfMAYANKBANSAL1981
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfMAYANKBANSAL1981
 
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdfAbout your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdfMAYANKBANSAL1981
 
About your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdfAbout your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdfMAYANKBANSAL1981
 
Answer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdfAnswer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdfMAYANKBANSAL1981
 
Advanced level school Python programming. Need helps. Thank.pdf
Advanced level school Python programming.  Need helps. Thank.pdfAdvanced level school Python programming.  Need helps. Thank.pdf
Advanced level school Python programming. Need helps. Thank.pdfMAYANKBANSAL1981
 

More from MAYANKBANSAL1981 (14)

Business management 1. True or False Diversification is when compa.pdf
Business management  1. True or False Diversification is when compa.pdfBusiness management  1. True or False Diversification is when compa.pdf
Business management 1. True or False Diversification is when compa.pdf
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdfCase Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
 
Can some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdfCan some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdf
 
Banks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdfBanks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdf
 
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdfASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
 
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdfA. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
 
About your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdfAbout your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdf
 
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdfAbout your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdfAbout your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
 
About your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdfAbout your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdf
 
Answer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdfAnswer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdf
 
Advanced level school Python programming. Need helps. Thank.pdf
Advanced level school Python programming.  Need helps. Thank.pdfAdvanced level school Python programming.  Need helps. Thank.pdf
Advanced level school Python programming. Need helps. Thank.pdf
 

Recently uploaded

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

Change to oop formatimport java.util.Scanner;import java.io.;.pdf

  • 1. Change to oop format import java.util.Scanner; import java.io.*; import java.text.DecimalFormat; public class Amortization { /* call values in, set balance and principle. set month to increment until reaching number provided. use t to space out result well. Use PritWriter output instead of System.output to make the notepad file.*/ public static void createReport(String filename, double loan, double interestRate, int years) throws IOException { PrintWriter output = new PrintWriter(new FileWriter(filename)); double monthlyPayment = calcPayment(loan, interestRate, years); int numberOfPayments = getNumberOfPayments(years); double balance = loan; output.println("{Monthly Payment}: " + monthlyPayment); output.println("{Month} t {Interest} t {Principal} t {Balance}"); for (int month = 1; month <= numberOfPayments; month++) { double interest = balance * (interestRate / 12); double principal = monthlyPayment - interest; balance -= principal; output.printf("%d t t %.2f t t %.2f t t %.2f n", month, interest, principal, balance); } output.close(); } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); DecimalFormat df = new DecimalFormat("#.##"); do { /* Data members */ double loan; int years; double interestRate;
  • 2. /* Get amount, interest rate, and years from the user */ System.out.println("Enter the loan amount: "); loan = keyboard.nextDouble(); System.out.println("Enter the annual interest rate: "); interestRate = keyboard.nextDouble() / 100.0; System.out.println("Enter the years of the loan: "); years = keyboard.nextInt(); double payment = calcPayment(loan, interestRate, years); if (payment < 0) { System.out.println("Invalid input values."); } else { System.out.println("Monthly Payment: " + df.format(payment)); int numberOfPayments = getNumberOfPayments(years); System.out.println("Total Number of Payments: " + numberOfPayments); try { createReport("LoanAmortization.txt", loan, interestRate, years); System.out.println("Report created successfully."); } catch (IOException e) { System.out.println("Error creating report: " + e.getMessage()); } } System.out.println("Would you like to run another report? Enter Y for yes or N for no: "); } while (keyboard.next().equalsIgnoreCase("Y")); keyboard.close(); } public static double calcPayment(double loan, double interestRate, int years) { double term = Math.pow(1 + (interestRate / 12), years * 12); double payment = (loan * (interestRate / 12) * term) / (term - 1); return payment; } public static int getNumberOfPayments(int years) { return years * 12; // Assuming monthly payments for the given number of years }
  • 3. public static void createReport(String filename) throws IOException { // Sample implementation to save data to a file PrintWriter out = new PrintWriter(new FileWriter(filename, true)); out.println("Sample Data"); out.close(); } }