SlideShare a Scribd company logo
This project calls for the modification of the "DollarFormat" class that is in listing 6.14 (p. 424-
425) of the textbook. Access the file named "DollarFormat.java" and modify as instructed in
the problem statement. Access the test application to test your modifications when you produce
"TruncatedDollarFormat". Start by going into JGRASP and open "DollarFormat.java",
rename the class to "TruncatedDollarFormat" and save the file as
"TruncatedDollarFormat.java", then make the necessary modifications as defined in the
problem statement, save and compile the file, then open the "TruncatedBankAccount"
application. Review the TruncatedBankAccount source code to see how each of the methods are
called. DO NOT make any changes to the TruncatedBankAccount application but instead modify
your TruncatedDollarFormat class to accommodate it.
this is the file that needs to be modified
public class TruncatedDollarFormat
{
/**
Displays amount in dollars and cents notation.
Rounds after two decimal places.
Does not advance to the next line after output.
*/
public static void write(double amount)
{
if (amount >= 0)
{
System.out.print('$');
writePositive(amount);
}
else
{
double positiveAmount = -amount;
System.out.print('$');
System.out.print('-');
writePositive(positiveAmount);
}
}
//Precondition: amount >= 0;
//Displays amount in dollars and cents notation. Rounds
//after two decimal places. Omits the dollar sign.
private static void writePositive(double amount)
{
int allCents = (int)(Math.round(amount * 100));
int dollars = allCents / 100;
int cents = allCents % 100;
System.out.print(dollars);
System.out.print('.');
if (cents < 10)
System.out.print('0');
System.out.print(cents);
}
/**
Displays amount in dollars and cents notation.
Rounds after two decimal points.
Advances to the next line after output.
*/
public static void writeln(double amount)
{
write(amount);
System.out.println( );
}
}
this is the test file
import java.util.*;
public class TruncatedBankAccount
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double initialBalance;
double interestRate;
double newBalance; // after 10 years
char answer; // sentinel to repeat or end program
int iteration; // loop counter
do // repeat entire program if user says yes
{
System.out.println("Please enter an initial balance "
+ "(dollars.cents):");
initialBalance = keyboard.nextDouble();
System.out.println
("Please enter an interest rate in percent "
+ "(e.g. 5.25):");
interestRate = keyboard.nextDouble();
System.out.print("In ten years an initial balance of ");
TruncatedDollarFormat.writeln(initialBalance);
System.out.println(" at an interest rate of "
+ interestRate + "% will be worth:");
// compound annually
newBalance = initialBalance;
for(iteration =1; iteration <= 10; ++iteration)
newBalance = newBalance
+ (interestRate/100) * newBalance;
TruncatedDollarFormat.write(newBalance);
System.out.println(" compounded annually");
// compound monthly
newBalance = initialBalance;
for(iteration =1; iteration <= 120; ++iteration)
newBalance = newBalance
+ (interestRate/12) * (newBalance/100);
TruncatedDollarFormat.write(newBalance);
System.out.println(" compounded monthly");
// compound daily
newBalance = initialBalance;
for(iteration =1; iteration <= 3650; ++iteration)
newBalance = newBalance
+ (interestRate/365) * (newBalance/100);
TruncatedDollarFormat.write(newBalance);
System.out.println(" compounded daily");
System.out.println();
System.out.println("Do you want to do it again?");
System.out.println("Enter y for yes or n for no.");
answer = keyboard.next().charAt(0);
}while ((answer == 'y') || (answer == 'Y'));
}
}
the output should look like this
Solution
Hi friend, I did not get your question/requirement.
The code that you have posted is working according to your requirement.
It produces required result.
Please let me know in case of any modification. Please specify your requirement clearly
################ TruncatedDollarFormat.java #############
public class TruncatedDollarFormat
{
/**
Displays amount in dollars and cents notation.
Rounds after two decimal places.
Does not advance to the next line after output.
*/
public static void write(double amount)
{
if (amount >= 0)
{
System.out.print('$');
writePositive(amount);
}
else
{
double positiveAmount = -amount;
System.out.print('$');
System.out.print('-');
writePositive(positiveAmount);
}
}
//Precondition: amount >= 0;
//Displays amount in dollars and cents notation. Rounds
//after two decimal places. Omits the dollar sign.
private static void writePositive(double amount)
{
int allCents = (int)(Math.round(amount * 100));
int dollars = allCents / 100;
int cents = allCents % 100;
System.out.print(dollars);
System.out.print('.');
if (cents < 10)
System.out.print('0');
System.out.print(cents);
}
/**
Displays amount in dollars and cents notation.
Rounds after two decimal points.
Advances to the next line after output.
*/
public static void writeln(double amount)
{
write(amount);
System.out.println( );
}
}
################# TruncatedBankAccount.java #################
import java.util.*;
public class TruncatedBankAccount
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double initialBalance;
double interestRate;
double newBalance; // after 10 years
char answer; // sentinel to repeat or end program
int iteration; // loop counter
do // repeat entire program if user says yes
{
System.out.println("Please enter an initial balance "
+ "(dollars.cents):");
initialBalance = keyboard.nextDouble();
System.out.println
("Please enter an interest rate in percent "
+ "(e.g. 5.25):");
interestRate = keyboard.nextDouble();
System.out.print("In ten years an initial balance of ");
TruncatedDollarFormat.writeln(initialBalance);
System.out.println(" at an interest rate of "
+ interestRate + "% will be worth:");
// compound annually
newBalance = initialBalance;
for(iteration =1; iteration <= 10; ++iteration)
newBalance = newBalance
+ (interestRate/100) * newBalance;
TruncatedDollarFormat.write(newBalance);
System.out.println(" compounded annually");
// compound monthly
newBalance = initialBalance;
for(iteration =1; iteration <= 120; ++iteration)
newBalance = newBalance
+ (interestRate/12) * (newBalance/100);
TruncatedDollarFormat.write(newBalance);
System.out.println(" compounded monthly");
// compound daily
newBalance = initialBalance;
for(iteration =1; iteration <= 3650; ++iteration)
newBalance = newBalance
+ (interestRate/365) * (newBalance/100);
TruncatedDollarFormat.write(newBalance);
System.out.println(" compounded daily");
System.out.println();
System.out.println("Do you want to do it again?");
System.out.println("Enter y for yes or n for no.");
answer = keyboard.next().charAt(0);
}while ((answer == 'y') || (answer == 'Y'));
}
}
/*
Sample Run:
Please enter an initial balance (dollars.cents):
1265.54
Please enter an interest rate in percent (e.g. 5.25):
5.43
In ten years an initial balance of $1265.54
at an interest rate of 5.43% will be worth:
$2147.42 compounded annually
$2175.53 compounded monthly
$2178.11 compounded daily
Do you want to do it again?
Enter y for yes or n for no.
n
*/

More Related Content

Similar to This project calls for the modification of the DollarFormat clas.pdf

1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
alanfhall8953
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgalyssa-castro2326
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
ssuser4fbfbf
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
RSathyaPriyaCSEKIOT
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
Doug Jones
 
Java programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdfJava programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdf
fathimafancy
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
You are to write a program that computes customers bill for hisher.docx
 You are to write a program that computes customers bill for hisher.docx You are to write a program that computes customers bill for hisher.docx
You are to write a program that computes customers bill for hisher.docx
ajoy21
 
I need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdfI need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
rajeshjangid1865
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
eaglesniper008
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
Mehul Desai
 

Similar to This project calls for the modification of the DollarFormat clas.pdf (20)

1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prg
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Presentation1
Presentation1Presentation1
Presentation1
 
CalculateLoanPayments
CalculateLoanPaymentsCalculateLoanPayments
CalculateLoanPayments
 
Java programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdfJava programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdf
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
You are to write a program that computes customers bill for hisher.docx
 You are to write a program that computes customers bill for hisher.docx You are to write a program that computes customers bill for hisher.docx
You are to write a program that computes customers bill for hisher.docx
 
I need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdfI need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 

More from jibinsh

What part of the brain is used in sympathetic arousal (ANS)Solu.pdf
What part of the brain is used in sympathetic arousal (ANS)Solu.pdfWhat part of the brain is used in sympathetic arousal (ANS)Solu.pdf
What part of the brain is used in sympathetic arousal (ANS)Solu.pdf
jibinsh
 
What type of cell-surface characteristic helps an epithelial tissue h.pdf
What type of cell-surface characteristic helps an epithelial tissue h.pdfWhat type of cell-surface characteristic helps an epithelial tissue h.pdf
What type of cell-surface characteristic helps an epithelial tissue h.pdf
jibinsh
 
Which bond would be most polar whySolutionstarting with .pdf
Which bond would be most polar whySolutionstarting with .pdfWhich bond would be most polar whySolutionstarting with .pdf
Which bond would be most polar whySolutionstarting with .pdf
jibinsh
 
What is NOT a requirement for evolution by natural selection to.pdf
What is NOT a requirement for evolution by natural selection to.pdfWhat is NOT a requirement for evolution by natural selection to.pdf
What is NOT a requirement for evolution by natural selection to.pdf
jibinsh
 
What is James Wilsons leadership style and traits What made him dif.pdf
What is James Wilsons leadership style and traits What made him dif.pdfWhat is James Wilsons leadership style and traits What made him dif.pdf
What is James Wilsons leadership style and traits What made him dif.pdf
jibinsh
 
The method FRET ALEX is a more precise way to determine the number o.pdf
The method FRET ALEX is a more precise way to determine the number o.pdfThe method FRET ALEX is a more precise way to determine the number o.pdf
The method FRET ALEX is a more precise way to determine the number o.pdf
jibinsh
 
The initial velocity is How do you solve the initial velocity.pdf
The initial velocity is How do you solve the initial velocity.pdfThe initial velocity is How do you solve the initial velocity.pdf
The initial velocity is How do you solve the initial velocity.pdf
jibinsh
 
The following expression was simplified incorrectly. In which line er.pdf
The following expression was simplified incorrectly. In which line er.pdfThe following expression was simplified incorrectly. In which line er.pdf
The following expression was simplified incorrectly. In which line er.pdf
jibinsh
 
The energy used in the CaMn cycle for the production of carbohydrate .pdf
The energy used in the CaMn cycle for the production of carbohydrate .pdfThe energy used in the CaMn cycle for the production of carbohydrate .pdf
The energy used in the CaMn cycle for the production of carbohydrate .pdf
jibinsh
 
The CAN-SPAM Acta.   applies to virtually all promotional e-mails,.pdf
The CAN-SPAM Acta.   applies to virtually all promotional e-mails,.pdfThe CAN-SPAM Acta.   applies to virtually all promotional e-mails,.pdf
The CAN-SPAM Acta.   applies to virtually all promotional e-mails,.pdf
jibinsh
 
SensesFor each of the special senses, understand how a stimulus is.pdf
SensesFor each of the special senses, understand how a stimulus is.pdfSensesFor each of the special senses, understand how a stimulus is.pdf
SensesFor each of the special senses, understand how a stimulus is.pdf
jibinsh
 
Recent Presidential debates have brought about a series of polls.pdf
Recent Presidential debates have brought about a series of polls.pdfRecent Presidential debates have brought about a series of polls.pdf
Recent Presidential debates have brought about a series of polls.pdf
jibinsh
 
Quality function deployment (QFD) is a structures approach for integ.pdf
Quality function deployment (QFD) is a structures approach for integ.pdfQuality function deployment (QFD) is a structures approach for integ.pdf
Quality function deployment (QFD) is a structures approach for integ.pdf
jibinsh
 
please send edited code. I have posted this a few times with lots of.pdf
please send edited code. I have posted this a few times with lots of.pdfplease send edited code. I have posted this a few times with lots of.pdf
please send edited code. I have posted this a few times with lots of.pdf
jibinsh
 
Please give me a custom example code of a complex PovRay Program tha.pdf
Please give me a custom example code of a complex PovRay Program tha.pdfPlease give me a custom example code of a complex PovRay Program tha.pdf
Please give me a custom example code of a complex PovRay Program tha.pdf
jibinsh
 
Networking Question What are the key differences between forwarding.pdf
Networking Question What are the key differences between forwarding.pdfNetworking Question What are the key differences between forwarding.pdf
Networking Question What are the key differences between forwarding.pdf
jibinsh
 
Most children with cystic fibrosis have frequent lung infections and.pdf
Most children with cystic fibrosis have frequent lung infections and.pdfMost children with cystic fibrosis have frequent lung infections and.pdf
Most children with cystic fibrosis have frequent lung infections and.pdf
jibinsh
 
A)abductionB)deductive reasoningc) inductive reasoningd)a wild.pdf
A)abductionB)deductive reasoningc) inductive reasoningd)a wild.pdfA)abductionB)deductive reasoningc) inductive reasoningd)a wild.pdf
A)abductionB)deductive reasoningc) inductive reasoningd)a wild.pdf
jibinsh
 
Lipid rafts are associated with which of the following activities re.pdf
Lipid rafts are associated with which of the following activities re.pdfLipid rafts are associated with which of the following activities re.pdf
Lipid rafts are associated with which of the following activities re.pdf
jibinsh
 
JAVAWrite a program that takes a command-line argument representin.pdf
JAVAWrite a program that takes a command-line argument representin.pdfJAVAWrite a program that takes a command-line argument representin.pdf
JAVAWrite a program that takes a command-line argument representin.pdf
jibinsh
 

More from jibinsh (20)

What part of the brain is used in sympathetic arousal (ANS)Solu.pdf
What part of the brain is used in sympathetic arousal (ANS)Solu.pdfWhat part of the brain is used in sympathetic arousal (ANS)Solu.pdf
What part of the brain is used in sympathetic arousal (ANS)Solu.pdf
 
What type of cell-surface characteristic helps an epithelial tissue h.pdf
What type of cell-surface characteristic helps an epithelial tissue h.pdfWhat type of cell-surface characteristic helps an epithelial tissue h.pdf
What type of cell-surface characteristic helps an epithelial tissue h.pdf
 
Which bond would be most polar whySolutionstarting with .pdf
Which bond would be most polar whySolutionstarting with .pdfWhich bond would be most polar whySolutionstarting with .pdf
Which bond would be most polar whySolutionstarting with .pdf
 
What is NOT a requirement for evolution by natural selection to.pdf
What is NOT a requirement for evolution by natural selection to.pdfWhat is NOT a requirement for evolution by natural selection to.pdf
What is NOT a requirement for evolution by natural selection to.pdf
 
What is James Wilsons leadership style and traits What made him dif.pdf
What is James Wilsons leadership style and traits What made him dif.pdfWhat is James Wilsons leadership style and traits What made him dif.pdf
What is James Wilsons leadership style and traits What made him dif.pdf
 
The method FRET ALEX is a more precise way to determine the number o.pdf
The method FRET ALEX is a more precise way to determine the number o.pdfThe method FRET ALEX is a more precise way to determine the number o.pdf
The method FRET ALEX is a more precise way to determine the number o.pdf
 
The initial velocity is How do you solve the initial velocity.pdf
The initial velocity is How do you solve the initial velocity.pdfThe initial velocity is How do you solve the initial velocity.pdf
The initial velocity is How do you solve the initial velocity.pdf
 
The following expression was simplified incorrectly. In which line er.pdf
The following expression was simplified incorrectly. In which line er.pdfThe following expression was simplified incorrectly. In which line er.pdf
The following expression was simplified incorrectly. In which line er.pdf
 
The energy used in the CaMn cycle for the production of carbohydrate .pdf
The energy used in the CaMn cycle for the production of carbohydrate .pdfThe energy used in the CaMn cycle for the production of carbohydrate .pdf
The energy used in the CaMn cycle for the production of carbohydrate .pdf
 
The CAN-SPAM Acta.   applies to virtually all promotional e-mails,.pdf
The CAN-SPAM Acta.   applies to virtually all promotional e-mails,.pdfThe CAN-SPAM Acta.   applies to virtually all promotional e-mails,.pdf
The CAN-SPAM Acta.   applies to virtually all promotional e-mails,.pdf
 
SensesFor each of the special senses, understand how a stimulus is.pdf
SensesFor each of the special senses, understand how a stimulus is.pdfSensesFor each of the special senses, understand how a stimulus is.pdf
SensesFor each of the special senses, understand how a stimulus is.pdf
 
Recent Presidential debates have brought about a series of polls.pdf
Recent Presidential debates have brought about a series of polls.pdfRecent Presidential debates have brought about a series of polls.pdf
Recent Presidential debates have brought about a series of polls.pdf
 
Quality function deployment (QFD) is a structures approach for integ.pdf
Quality function deployment (QFD) is a structures approach for integ.pdfQuality function deployment (QFD) is a structures approach for integ.pdf
Quality function deployment (QFD) is a structures approach for integ.pdf
 
please send edited code. I have posted this a few times with lots of.pdf
please send edited code. I have posted this a few times with lots of.pdfplease send edited code. I have posted this a few times with lots of.pdf
please send edited code. I have posted this a few times with lots of.pdf
 
Please give me a custom example code of a complex PovRay Program tha.pdf
Please give me a custom example code of a complex PovRay Program tha.pdfPlease give me a custom example code of a complex PovRay Program tha.pdf
Please give me a custom example code of a complex PovRay Program tha.pdf
 
Networking Question What are the key differences between forwarding.pdf
Networking Question What are the key differences between forwarding.pdfNetworking Question What are the key differences between forwarding.pdf
Networking Question What are the key differences between forwarding.pdf
 
Most children with cystic fibrosis have frequent lung infections and.pdf
Most children with cystic fibrosis have frequent lung infections and.pdfMost children with cystic fibrosis have frequent lung infections and.pdf
Most children with cystic fibrosis have frequent lung infections and.pdf
 
A)abductionB)deductive reasoningc) inductive reasoningd)a wild.pdf
A)abductionB)deductive reasoningc) inductive reasoningd)a wild.pdfA)abductionB)deductive reasoningc) inductive reasoningd)a wild.pdf
A)abductionB)deductive reasoningc) inductive reasoningd)a wild.pdf
 
Lipid rafts are associated with which of the following activities re.pdf
Lipid rafts are associated with which of the following activities re.pdfLipid rafts are associated with which of the following activities re.pdf
Lipid rafts are associated with which of the following activities re.pdf
 
JAVAWrite a program that takes a command-line argument representin.pdf
JAVAWrite a program that takes a command-line argument representin.pdfJAVAWrite a program that takes a command-line argument representin.pdf
JAVAWrite a program that takes a command-line argument representin.pdf
 

Recently uploaded

Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 

Recently uploaded (20)

Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

This project calls for the modification of the DollarFormat clas.pdf

  • 1. This project calls for the modification of the "DollarFormat" class that is in listing 6.14 (p. 424- 425) of the textbook. Access the file named "DollarFormat.java" and modify as instructed in the problem statement. Access the test application to test your modifications when you produce "TruncatedDollarFormat". Start by going into JGRASP and open "DollarFormat.java", rename the class to "TruncatedDollarFormat" and save the file as "TruncatedDollarFormat.java", then make the necessary modifications as defined in the problem statement, save and compile the file, then open the "TruncatedBankAccount" application. Review the TruncatedBankAccount source code to see how each of the methods are called. DO NOT make any changes to the TruncatedBankAccount application but instead modify your TruncatedDollarFormat class to accommodate it. this is the file that needs to be modified public class TruncatedDollarFormat { /** Displays amount in dollars and cents notation. Rounds after two decimal places. Does not advance to the next line after output. */ public static void write(double amount) { if (amount >= 0) { System.out.print('$'); writePositive(amount); } else { double positiveAmount = -amount; System.out.print('$'); System.out.print('-'); writePositive(positiveAmount); } }
  • 2. //Precondition: amount >= 0; //Displays amount in dollars and cents notation. Rounds //after two decimal places. Omits the dollar sign. private static void writePositive(double amount) { int allCents = (int)(Math.round(amount * 100)); int dollars = allCents / 100; int cents = allCents % 100; System.out.print(dollars); System.out.print('.'); if (cents < 10) System.out.print('0'); System.out.print(cents); } /** Displays amount in dollars and cents notation. Rounds after two decimal points. Advances to the next line after output. */ public static void writeln(double amount) { write(amount); System.out.println( ); } } this is the test file import java.util.*; public class TruncatedBankAccount { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in);
  • 3. double initialBalance; double interestRate; double newBalance; // after 10 years char answer; // sentinel to repeat or end program int iteration; // loop counter do // repeat entire program if user says yes { System.out.println("Please enter an initial balance " + "(dollars.cents):"); initialBalance = keyboard.nextDouble(); System.out.println ("Please enter an interest rate in percent " + "(e.g. 5.25):"); interestRate = keyboard.nextDouble(); System.out.print("In ten years an initial balance of "); TruncatedDollarFormat.writeln(initialBalance); System.out.println(" at an interest rate of " + interestRate + "% will be worth:"); // compound annually newBalance = initialBalance; for(iteration =1; iteration <= 10; ++iteration) newBalance = newBalance + (interestRate/100) * newBalance; TruncatedDollarFormat.write(newBalance); System.out.println(" compounded annually"); // compound monthly newBalance = initialBalance; for(iteration =1; iteration <= 120; ++iteration) newBalance = newBalance + (interestRate/12) * (newBalance/100); TruncatedDollarFormat.write(newBalance);
  • 4. System.out.println(" compounded monthly"); // compound daily newBalance = initialBalance; for(iteration =1; iteration <= 3650; ++iteration) newBalance = newBalance + (interestRate/365) * (newBalance/100); TruncatedDollarFormat.write(newBalance); System.out.println(" compounded daily"); System.out.println(); System.out.println("Do you want to do it again?"); System.out.println("Enter y for yes or n for no."); answer = keyboard.next().charAt(0); }while ((answer == 'y') || (answer == 'Y')); } } the output should look like this Solution Hi friend, I did not get your question/requirement. The code that you have posted is working according to your requirement. It produces required result. Please let me know in case of any modification. Please specify your requirement clearly ################ TruncatedDollarFormat.java ############# public class TruncatedDollarFormat { /** Displays amount in dollars and cents notation. Rounds after two decimal places. Does not advance to the next line after output. */ public static void write(double amount) { if (amount >= 0)
  • 5. { System.out.print('$'); writePositive(amount); } else { double positiveAmount = -amount; System.out.print('$'); System.out.print('-'); writePositive(positiveAmount); } } //Precondition: amount >= 0; //Displays amount in dollars and cents notation. Rounds //after two decimal places. Omits the dollar sign. private static void writePositive(double amount) { int allCents = (int)(Math.round(amount * 100)); int dollars = allCents / 100; int cents = allCents % 100; System.out.print(dollars); System.out.print('.'); if (cents < 10) System.out.print('0'); System.out.print(cents); } /** Displays amount in dollars and cents notation. Rounds after two decimal points. Advances to the next line after output. */ public static void writeln(double amount) { write(amount); System.out.println( ); }
  • 6. } ################# TruncatedBankAccount.java ################# import java.util.*; public class TruncatedBankAccount { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); double initialBalance; double interestRate; double newBalance; // after 10 years char answer; // sentinel to repeat or end program int iteration; // loop counter do // repeat entire program if user says yes { System.out.println("Please enter an initial balance " + "(dollars.cents):"); initialBalance = keyboard.nextDouble(); System.out.println ("Please enter an interest rate in percent " + "(e.g. 5.25):"); interestRate = keyboard.nextDouble(); System.out.print("In ten years an initial balance of "); TruncatedDollarFormat.writeln(initialBalance); System.out.println(" at an interest rate of " + interestRate + "% will be worth:"); // compound annually newBalance = initialBalance; for(iteration =1; iteration <= 10; ++iteration) newBalance = newBalance + (interestRate/100) * newBalance; TruncatedDollarFormat.write(newBalance); System.out.println(" compounded annually"); // compound monthly newBalance = initialBalance; for(iteration =1; iteration <= 120; ++iteration)
  • 7. newBalance = newBalance + (interestRate/12) * (newBalance/100); TruncatedDollarFormat.write(newBalance); System.out.println(" compounded monthly"); // compound daily newBalance = initialBalance; for(iteration =1; iteration <= 3650; ++iteration) newBalance = newBalance + (interestRate/365) * (newBalance/100); TruncatedDollarFormat.write(newBalance); System.out.println(" compounded daily"); System.out.println(); System.out.println("Do you want to do it again?"); System.out.println("Enter y for yes or n for no."); answer = keyboard.next().charAt(0); }while ((answer == 'y') || (answer == 'Y')); } } /* Sample Run: Please enter an initial balance (dollars.cents): 1265.54 Please enter an interest rate in percent (e.g. 5.25): 5.43 In ten years an initial balance of $1265.54 at an interest rate of 5.43% will be worth: $2147.42 compounded annually $2175.53 compounded monthly $2178.11 compounded daily Do you want to do it again? Enter y for yes or n for no. n */