Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import javax.swing.JOptionPane; public class PetFoodArrow { public static void main ( String [ ] args ) { String input = ; char foodGrade

import javax.swing.JOptionPane;
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 foodGradeInput;
String[] mssgs ={ "Our pet food is available in grades A, B, and C.",
"Which do you want pricing for? {X to stop}: "};
foodGradeInput = JOptionPane.showInputDialog(mssgs[0]+(char)10+ mssgs[1]);
return foodGradeInput.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.
"};
JOptionPane.showMessageDialog(null, iO);
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);
}
}
/**
Average class
*/
public class Average
{
private double akkum;
private int Count;
public Average()// Constructor; initializes the class fields
{
akkum =0.0;
Count =0;
}
public void setSum(double num1)// Mutator Method (Setter)
{
akkum += num1; // This double field is accumulating the values of the numbers entered
}
public void setCount()// Mutator Method (Setter)
{
Count++; // This integer counts how many values have been read
}
public double getSum()// Accessor Method (Getter)
{
return akkum; // This double value represents the sum of all the numbers to be averaged
}
public int getCount()// Accessor Method (Getter)
{
return Count; // This integer value represents how many numbers have been entered
}
public double getAvg()// Accessor Method (Getter)
{
return akkum / Count; // This double value represents the calculated Average; prevents stale data
}
}
image text in transcribed

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

c. Acafeteriawhere healthy, nutritionally balanced foods are served

Answered: 1 week ago

Question

c. What steps can you take to help eliminate the stress?

Answered: 1 week ago