yrstruly Posted May 3, 2009 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)
Jack McKalling Posted September 1, 2009 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()); }}
Recommended Posts
Archived
This topic is now archived and is closed to further replies.