Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import java.util.Scanner; public class EggGradingSystem { static int countA = 0, countB = 0, countC = 0, countD = 0; static double totalA = 0, totalB = 0, totalC = 0, totalD = 0; // i. Method to determine grade and calculate total weight of each grade public static char getGrade(double weight) { if (weight > 44) { totalA += weight; return 'A'; } else if (weight >= 30) { totalB += weight; return 'B'; } else if (weight >= 25) { totalC += weight; return 'C'; } else { totalD += weight; return 'D'; } } // ii. Method to count total eggs for each grade public static void countGrade(char grade) { switch (grade) { case 'A': countA++; break; case 'B': countB++; break; case 'C': countC++; break; case 'D': countD++; break; } } // iii. Method to display report public static void displayReport() { double totalWeight = totalA + totalB + totalC + totalD; System.out.println("\n===== EGGS GRADING REPORT ====="); System.out.println("Grade A: " + countA + " eggs, Average weight = " + (countA > 0 ? totalA / countA : 0)); System.out.println("Grade B: " + countB + " eggs, Average weight = " + (countB > 0 ? totalB / countB : 0)); System.out.println("Grade C: " + countC + " eggs, Average weight = " + (countC > 0 ? totalC / countC : 0)); System.out.println("Grade D (Rejected): " + countD + " eggs, Average weight = " + (countD > 0 ? totalD / countD : 0)); System.out.println("Total weight of all eggs: " + totalWeight + " g"); } // main method public static void main(String[] args) { Scanner sc = new Scanner(System.in); double weight; char grade; for (int i = 1; i <= 10; i++) { System.out.print("Enter weight for egg " + i + " (g): "); weight = sc.nextDouble(); grade = getGrade(weight); countGrade(grade); } displayReport(); sc.close(); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)