SlideShare a Scribd company logo
1 of 7
Download to read offline
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 MODIFY DOLLAR FORMAT

1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxalanfhall8953
 
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
 
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.pdffathimafancy
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana 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.docxajoy21
 
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.pdfrajeshjangid1865
 
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 cTushar 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 .pdfmayorothenguyenhob69
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptxeaglesniper008
 

Similar to MODIFY DOLLAR FORMAT (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.pdfjibinsh
 
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.pdfjibinsh
 
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 .pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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 .pdfjibinsh
 
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,.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 
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.pdfjibinsh
 

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

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
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
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
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 🔝✔️✔️
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
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🔝
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

MODIFY DOLLAR FORMAT

  • 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 */