Hi, I just started college recently and Java is on the course. Unfortunately I am not yet very adept at Java and I'm having difficulty with a simple program.
The program is supposed to count the amount of boxes needed to deliver eggs by the dozen, and to calculate the number of leftovers which wont fill a box.
If anyone could help me I would be very appreciative.
Eggs.java
/*
*EggBoxes.java
*@author Seán
*4th October 2012
*/
public class Eggs{
//declare data members
private int eggs;
private int boxes;
private int leftovers;
private int totalBoxes;
private int totalLeftovers;
//constructor
public Eggs(){
eggs = 0;
boxes = 0;
leftovers = 0;
}
//set method - one for every input variable
public void setEggs(int eggs){
this.eggs = eggs;
}
//compute method
public void computeBoxes(){
boxes = eggs / 12;
totalBoxes = boxes;
}
public void computeLeftovers(){
leftovers = eggs - (eggs / 12);
totalLeftovers = leftovers;
}
//get method(s)
public int getBoxes(){
return boxes;
}
public int getLeftovers(){
return leftovers;
}
}
EggsApp.java
/*
*EggsApp.java
*@author Seán
*4th October 2012
*/
import java.util.Scanner;
public class EggsApp{
public static void main(String args[]){
//declare variables
int eggs, boxes, leftovers;
//declare objects
Scanner keyboard;
Eggs myEggs;
//create objects
keyboard = new Scanner(System.in);
myEggs = new Eggs();
//input
System.out.println("Please enter the amount of eggs you have");
eggs = keyboard.nextInt();
myEggs.setEggs(eggs);
//process
myEggs.computeBoxes();
myEggs.computeLeftovers();
//output
Boxes = myEggs.getTotalBoxes;
System.out.println("The number of boxes required is"+boxes);
Leftovers = myEggs.getTotalLeftovers;
System.out.println("The number of eggs leftover is"+leftovers);
}
}
Thank you in advance.
The program is supposed to count the amount of boxes needed to deliver eggs by the dozen, and to calculate the number of leftovers which wont fill a box.
If anyone could help me I would be very appreciative.
Eggs.java
/*
*EggBoxes.java
*@author Seán
*4th October 2012
*/
public class Eggs{
//declare data members
private int eggs;
private int boxes;
private int leftovers;
private int totalBoxes;
private int totalLeftovers;
//constructor
public Eggs(){
eggs = 0;
boxes = 0;
leftovers = 0;
}
//set method - one for every input variable
public void setEggs(int eggs){
this.eggs = eggs;
}
//compute method
public void computeBoxes(){
boxes = eggs / 12;
totalBoxes = boxes;
}
public void computeLeftovers(){
leftovers = eggs - (eggs / 12);
totalLeftovers = leftovers;
}
//get method(s)
public int getBoxes(){
return boxes;
}
public int getLeftovers(){
return leftovers;
}
}
EggsApp.java
/*
*EggsApp.java
*@author Seán
*4th October 2012
*/
import java.util.Scanner;
public class EggsApp{
public static void main(String args[]){
//declare variables
int eggs, boxes, leftovers;
//declare objects
Scanner keyboard;
Eggs myEggs;
//create objects
keyboard = new Scanner(System.in);
myEggs = new Eggs();
//input
System.out.println("Please enter the amount of eggs you have");
eggs = keyboard.nextInt();
myEggs.setEggs(eggs);
//process
myEggs.computeBoxes();
myEggs.computeLeftovers();
//output
Boxes = myEggs.getTotalBoxes;
System.out.println("The number of boxes required is"+boxes);
Leftovers = myEggs.getTotalLeftovers;
System.out.println("The number of eggs leftover is"+leftovers);
}
}
Thank you in advance.