Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class PetFoodArrow { public static void main(String[] args) { String input = ; char foodGrade = ' '; foodGrade = getInput(); while(foodGrade

import java.util.Scanner; public class PetFoodArrow { public static void main(String[] args) { String input = ""; char foodGrade = ' '; foodGrade = getInput(); while(foodGrade != 'X') { input = getGrade(foodGrade); prinout(foodGrade, input); foodGrade = getInput(); } input = " End of the program! "; prinout(foodGrade, input); } /* Methods' Definitions */ public static char getInput() { String[] mssgs = { "Our pet food is available in grades A, B, and C.", "Which do you want pricing for? {X to stop}: "}; Scanner keyboard = new Scanner(System.in); System.out.print(mssgs[0] + (char)10 + mssgs[1]); return keyboard.nextLine().toUpperCase().charAt(0); } public static String getGrade(char fudGrade) { String iO = ""; String[] messash = { " Food grade ", " costs 30 cents per lb. ", " costs 20 cents per lb. ", " costs 15 cents per lb. ", " Invalid choice. " }; iO = switch(fudGrade) { case 'A' -> messash[0] + fudGrade + messash[1]; case 'B'-> messash[0] + fudGrade + messash[2]; case 'C' -> messash[0] + fudGrade + messash[3]; default -> messash[4]; }; return iO; } public static void prinout(char fudGr, String incoming) { if(fudGr != 'X') System.out.println(incoming); else System.out.println(incoming); } } Use the program in the PetFoodArrow and make the following modifications: a. Change it so that it uses JOptionPanes for input and output instead of Scanners b. Rename it PetFoodFin c. Prompt the user for the pet food grade AND the number of pounds they want to purchase d. Calculate the bill for the purchase by multiplying the price per-pound by the pounds purchased e. Change the switch statement to a switch expression that returns a double value containing the price; the default case should return a 0.0 f. Your program should handle the possibility that users might enter lower case characters for the pet food grade g. Write a local method named getInput() that uses a conditional operator to prompt you to enter the pet food grade or the number of pounds the client wants to purchase. In this method declare an icon using the image puppy.jpg and a String array that contains the following elements: " Our pet food is available in three grades: ", "A, B, and C. Which do you want pricing for? {Enter X to stop}? ", " How many pounds do you want? " h. Write another local method named prinout() that displays the cost of each grade of pet food and the cost of the poundage purchased or displays the average sales value. In this method declare an icon using the image puppy.jpg and a String array that contains the following elements: Grade ", " sells for ", "Your ", " lbs. purchase = ", " cents per lb.", " The average sales totaled ", "Summary Screen" and "Average Screen" i. Create a class named PetFood using the UML diagram below:

image text in transcribed

j. Use the PetFood class in your main method as well as the Average class to accumulate, count and average total purchases. k. The switch expression will be contained in the getPrice() method l. If the price returned by getPrice() is zero, dont prompt for the pounds, dont calculate the total cost, dont accumulate or count; just print a message that says Invalid choice!

image text in transcribedimage text in transcribed

image text in transcribed image text in transcribed

\begin{tabular}{l} PetFood \\ \hline - price : double \\ - libs : double \\ - gotInfo : boolean \\ + PetFood() \\ + setBull(ge : boolean) : void \\ + getBull () : Boolean \\ + getPrice(fG : char) : double \\ + calcBill(pounds : String) : double \end{tabular} Input ? Our pet food is available in three grades: A, B, and C. Which do you want pricing for? \{Enter X to stop\}? OK Cancel \begin{tabular}{|c|c|} \hline Input \\ OK & \\ & How many pounds do you want? \\ \hline \end{tabular} \begin{tabular}{|l|l|} \hline Average Screen \\ \hline OK \\ \hline \end{tabular} Grade A sells for $0.30 cents per lb. Your 10.00 lbs. purchase =$3.00 OK

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions