Question
2.22 Lab 2b: Evaluating Word Problems A brief note from your instructor: SUBMISSION HELP Please do not spend loads of time trying to get floating-point
2.22 Lab 2b: Evaluating Word Problems
A brief note from your instructor:
SUBMISSION HELP
Please do not spend loads of time trying to get floating-point values to work out with complete precision. We will examine your program for correctness visually.
The best way to let us know you have the "right answer but are not getting the points" is to FOR EACH OCURRANCE, MAKE A COMMENT IN THE CODE TO EXPLAIN THE SITUATION. Then the grader will know exactly where to examine and can award missing points.
Introduction
Now that you've had practice translating some simple equations, let's give some context to the math and solve some word problems. Don't forget you'll need to use a Scanner to get the values for the variables. Refer back to the previous lab if you need some help writing the code for it.
Task
Problem A
Jimmy and 4 of his friends are at the movies and he was asked to purchase the snacks. The prices are as follows:
popcorn: $5.75 candy bar: $1 soda: $1.50 water: $1
Calculate the price of buying p bags of popcorn, c candy bars, s sodas, and w waters.
They all agreed to split the price evenly, calculate the amount each person should pay.
Problem B
Jane is planning to put a new fence around her flower garden. She wants to change the shape, but doesn't want to change the amount of space it occupies. It is currently a square that has sides of length squareSide. She wants to make it a rectangle with one set of parallel sides twice the length of the other set of parallel sides. What should the length of the sides be?
Data Type Hint: Can you purchase half a bag of popcorn/cand bar/soda/water? Does it make sense to have decimals for these variables? What about for the price or the length of a fence side?
public class WordProblems { public static void main(String[] args) { //ID comment goes here!!!!! /* Your variables go here! Including the Scanner*/ /*Solution to Problem A the numbers are read in the order of price listing (p,c,s,w)*/ System.out.println("Price of the snack: $" + /*your variable(s) name*/); System.out.println("Individual price: $" + /*your variable(s) here*/); /*Solution to Problem B Note: the squareroot function is Math.sqrt(variable) */ System.out.println("Length of long side: " + /*your variable here*/); System.out.println("Length of short side: " + /*your variable here*/); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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