Jump to content

Recommended Posts

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 post
Share on other sites
  • 3 months later...

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...