Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using the following program make the modifications below: import java.util.Scanner; public class PetFoodArrow { public static void main ( String [ ] args ) {
Using the following program make the modifications below: import java.util.Scanner;
public class PetFoodArrow
public static void mainString args
String input ;
char foodGrade ;
foodGrade getInput;
whilefoodGrade X
input getGradefoodGrade;
prinoutfoodGrade input;
foodGrade getInput;
input
End of the program!
;
prinoutfoodGrade 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 ScannerSystemin;
System.out.printmssgschar mssgs;
return keyboard.nextLinetoUpperCasecharAt;
public static String getGradechar fudGrade
String iO ;
String messash
Food grade costs cents per lb
costs cents per lb
costs cents per lb
Invalid choice.
;
iO switchfudGrade
case A messash fudGrade messash;
case B messash fudGrade messash;
case C messash fudGrade messash;
default messash;
;
return iO;
public static void prinoutchar fudGr, String incoming
iffudGr X
System.out.printlnincoming;
else
System.out.printlnincoming;
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 perpound 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
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:
"InOur pet food is available in three grades:", A B and C InWhich do you want pricing for? Enter X to stop "InHow 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:
"InGrade "sells for "Your "Ibs. purchase "cents per Ib "InThe average sales totaled "Summary Screen" and "Average Screen"
i Create a class named PetFood using the UML diagram below:.
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
I. If the price returned by getPrice is zero, don't prompt for the pounds, don't calculate the total cost, don't accumulate or count; just print a message that says "Invalid
choice!".
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