yrstruly Posted May 3, 2009 Report Share Posted May 3, 2009 If i have a code like the following, how would i begin it. Is there somebody who could help me please or just show some guidance?Create a class named Eggs. It's main() method holds an integer variable named numberOfEggs to which you will assign a value. Create a method to which you pass numberOfEggs. The method displays the eggs in dozens; for example, 50 eggs is four full dozen (with two eggs remaining) Link to comment Share on other sites More sharing options...
Jack McKalling Posted September 1, 2009 Report Share Posted September 1, 2009 Could this help: public class Eggs{ //some field members here private int amount; ... public Eggs() { //constructor of the class //initialise field members here //ie. give them a default value this.amount = 0; } public void setAmount(int newAmount) { this.amount = newAmount; } public int getAmountInDozens() { return (int) Math.floor(this.amount / 12); } public static void main(String[] args) { Eggs eggs = new Eggs(); eggs.setAmount(50); System.out.println(eggs.getAmountInDozens()); }} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now