Question
I need help with Part 1 it's supposed to be in Java but im lost! Here's the code I'm working with! import java.util.Scanner; public class
I need help with Part 1 it's supposed to be in Java but im lost! Here's the code I'm working with!
import java.util.Scanner;
public class Chickens {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true){
System.out.print("Enter the number of chickens: ");
int chickens = scanner.nextInt();
if (chickens == 0) break;
System.out.print("Enter average # of eggs per chicken per day: ");
double eggsRate = scanner.nextDouble();
System.out.print("Enter pounds needed to feed per chicken per day: ");
double pounds = scanner.nextDouble();
System.out.print("Enter cost per pound for feed: ");
double costPerPound = scanner.nextDouble();
System.out.print("Enter empty cartoon cost: ");
double cartoonCost = scanner.nextDouble();
double totalCostinMonth = chickens * pounds * costPerPound * 30 + cartoonCost;
double dozenEggCost = (12 * totalCostinMonth) / (chickens * eggsRate * 30);
System.out.println("Number of chickens: " + chickens);
System.out.println("Average # of eggs per chicken per day: " + eggsRate);
System.out.println("Pounds needed to feed per chicken per day: " + pounds + " lbs");
System.out.println("Cost per pound $" + costPerPound);
System.out.println("Empty cartoon cost: $" + cartoonCost);
System.out.println("Total feed cost per month: $" + totalCostinMonth);
System.out.println("Cost to produce 12 eggs: " + dozenEggCost);
System.out.println();
//Part2
System.out.printf("%10s %10s %15s ", "Percent", "Feed Cost", "Dozen Egg Cost");
double feedCost , eggCost;
for(double percent = -0.25; percent <= 0.25; percent += 0.05) {
feedCost = (1+percent) * totalCostinMonth;
eggCost = (12 * feedCost) / (chickens * eggsRate * 30);
// double %% is used to print % symbol.
// %10.2f prints in 10column with 2 decimal places
System.out.printf("%10.2f%% %10.2f %15.2f ", percent, feedCost, eggCost);
}
}
System.out.println("Bye!");
}
}
Part 1:
Starting with the solution to Assignment 2, re-factor the program to do the following:
- Store the parameters (number of chickens, eggs laid per day, etc.,) in static fields of the class.
- Have separate methods for updating the parameters.
- Use a switch statement to take menu selections for updating parameters or outputting results.
- If the menu choice is 0, the program should terminate, invalid inputs should be ignored and any prompt repeated.
- Before displaying updated menu, clear the screen
Part 2:
Using UMLet or Draw.IO, draw an Activity Diagram of the while loop.
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