Help With Java Program(s): Beginner

Discussion in 'Java' started by Q1uic, Oct 6, 2012.

  1. Q1uic

    Q1uic

    Joined:
    Oct 6, 2012
    Messages:
    1
    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.
    Q1uic, Oct 6, 2012
    #1
    1. Advertising

  2. Q1uic

    1968

    Joined:
    Oct 8, 2012
    Messages:
    5
    I want to listen to music on my phone, I have no idea what to do please help

    Music on my phone? How do I do this? I have no idea what to do - please help a person who knows nothing about phones/computers or any thing like that! My kids have always looked after these things for me but they have grown up and left home so it's time to learn for my self.
    1968, Oct 8, 2012
    #2
    1. Advertising

  3. Q1uic

    1968

    Joined:
    Oct 8, 2012
    Messages:
    5
    I do I read my reply, if I have one??

    Please will some one tell me how to work this bloody phone, I've been trying now for hours, how do I find my reply.
    1968, Oct 8, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    572
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  2. Rey
    Replies:
    4
    Views:
    10,939
    Roedy Green
    Dec 12, 2003
  3. cjeffwang@yahoo.com
    Replies:
    1
    Views:
    512
    Andrew Thompson
    Oct 31, 2005
  4. Rensjuh
    Replies:
    7
    Views:
    964
    Mabden
    Sep 2, 2004
  5. william nelson

    Beginner's Beginner

    william nelson, Apr 11, 2011, in forum: Ruby
    Replies:
    7
    Views:
    213
    7stud --
    Apr 12, 2011
Loading...

Share This Page