Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Description Write a program to calculate the purchase cost ofthree different books that are beingordered. You may select yourfavorite books (use prices from online

Java

image text in transcribed

Description Write a program to calculate the purchase cost ofthree different books that are beingordered. You may select yourfavorite books (use prices from online book sellers), but I've included some of my favorite Java books below. This is how your program should work. You may change the names and costs of the books (in fact, do it-it will tell us something about what you're interested in), but do not change the wording Purchase1 copy of Design Patterns: Elements of Reusable Object-Oriented Software by Gamma, Helm, Johnsonand Vlissides. Each copycosts $32.46. Purchase 2 copies of Effective Java by Bloch. Each copy costs 35.48 Purchase 4 copies of Java Puzzlers: Traps, Pitfalls and CornerCases by Bloch and Gafter. Each copy costs $27.86. The total cost ofyour purchases is: $214.86. Sales tax is: $13.97 The total cost ofyourorder will be: $228.82 You should have variables that hold the number of copies of each book purchased, and constants that hold the costs of the books. There should be a variable forthe final purchase price. The sales tax rate is 6.5% and is a constant. Gettingdouble values to print out nicely is done by separatingdollars from cents. Considerthe mathematics below: The first thing that needstobe done is getting rid of the excess decimal places. 2228.82S9100 22882.59 If you truncate 22882.59 to an int using a cast, you'd get 22882.1 Printing this out as dollars and cents requires a trick. We need to change 22882 to a String, and print out the first digits separate from the lasttwo. String money22882; //you'll use a variable instead of the numberhere String dollars money.substring(0, money.length() -2): //take all but the last two digits String cents money.substring(money.length()-2, money.length)): //grab the last twodigits System.out.println(dollars"" +cents); /+means concatenate-orto put Strings togetherend to end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions