Jump to content

Class Name


yrstruly

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...