Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write two types of java codes with following condition with different flow chart: For an ordinary letter up to 3.5 ounces, the cost is .47
Write two types of java codes with following condition with different flow chart:
For an ordinary letter up to 3.5 ounces, the cost is .47 plus .21 for each additional ounce (or part of an ounce). Try some examples: - A letter that is 1 ounce (or less) is just .47. - For a 3 ounce letter the cost is .47+(2.21)=.89 - For a 2.3 ounce letter, the cost is also .47+(2.21)=.89, since 1.3 rounds up to 2 - For a 3.1 ounce letter the cost is .47+(3.21)=1.10, since 2.1 rounds up to 3 To translate this into code, it would be nice to have a slick way to take a float value and round "up" to the next whole number. Fortunately there is a function in the Math class, called ceil() (short for ceiling ) that does exactly what we want. Try executing these statements: Now, to make things more interesting, let's add the rule for letters over 3.5 ounces: the cost is .94 plus .21 for each additional ounce (or part of an ounce). For example, - a 3.5 ounce letter would cost .47+(3.21)=1.10, using the first rule - a 3.8 ounce letter would cost .94+(3.21)=1.57 - a 10 ounce letter would cost .94+(9.21)=2.83 Notice you have to check the actual weight to see if it is bigger than 3.5, but then round up when you calculate the extra ounces. Flowchart 1 (below) return cost Flowchart 2 (below)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started