0% found this document useful (0 votes)
3 views1 page

Untitled Document

The document defines a Cereal class with attributes for calories, fat, sugar, weight, and rating. It includes methods to retrieve these attributes and a constructor to initialize them. Additionally, there is a main method for testing the creation and display of Cereal objects.

Uploaded by

kmrea01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Untitled Document

The document defines a Cereal class with attributes for calories, fat, sugar, weight, and rating. It includes methods to retrieve these attributes and a constructor to initialize them. Additionally, there is a main method for testing the creation and display of Cereal objects.

Uploaded by

kmrea01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

public class Cereal { }

private int calories;


private double fat; public double getRating() {
private int sugar; return rating;
private double weight; }
private double rating;
@Override
public Cereal(int calories, double fat, int public String toString() {
sugar, double weight, double rating) { return "Cereal{" +
this.calories = calories; "calories=" + calories +
this.fat = fat; ", fat=" + fat +
this.sugar = sugar; ", sugar=" + sugar +
this.weight = weight; ", weight=" + weight +
this.rating = rating; ", rating=" + rating +
} '}';
}
public int getCalories() {
return calories; // Main method for testing
} public static void main(String[] args) {
Cereal cereal1 = new Cereal(70, 1.0,
public double getFat() { 6, 1.0, 68.402973);
return fat; Cereal cereal2 = new Cereal(120, 5.0,
} 8, 1.0, 33.983679);
Cereal cereal3 = new Cereal(50, 0.0,
public int getSugar() { 0, 1.0, 93.704912);
return sugar;
} System.out.println(cereal1);
System.out.println(cereal2);
public double getWeight() { System.out.println(cereal3);
return weight; }
}

You might also like