954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I am so confused!

I am taking an online java programming class this quarter and the book I have just does not do a good job of explaining anything! The more I read it, the more confused I become!

Can someone refer me to an article or site that explains creating methods in terms that are easy to understand? I'll post a copy of my assignment below so you can have an idea of what Im looking for..

Create a class named Eggs. Its main() method holds an integer vaiable 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 4 full dozen with two left over.

Save the program as Eggs.java.

girlinwayside
Newbie Poster
8 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

You may want to review some of the material in the "Starting Java" thread that is stickied at the top of the forum for basics.

What part of the assignment do you not understand? What do you have so far?

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

I am really confused about the whole deal. This is only the second week of the class and I haven't been able to grasp the idea of any of it thus far. :(
I dont understand what it means by "passing"

This is what I have so far.

public class Eggs
{

public static void main(String[] args)
{
int numberofEggs = 25;

System.out.println("25 eggs are two full dozen plus one");

}
}

Ill go read though that thread.. thanks

girlinwayside
Newbie Poster
8 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 
Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

They mean make a method that has a parameter, numberOfEggs, which is an integer.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

try to read in elliot coffman book in java its very simple to understand
public class eggs
{public static void main(String args [])
{
int NumberOfEggs =25;
System.out.print("Full dozen"+ duzen(NumberOfEggs ) );
}
public int duzen( int x)
{return x/12; }
}

doleh
Newbie Poster
9 posts since Jul 2008
Reputation Points: 8
Solved Threads: 1
 

it is OK the beginning always be like that

you may want to try read this, I had when I was in my earlier weeks

http://www.freejavaguide.com/corejava.htm

also the Deitel and Deitel resource are worthy to read
if you have visited that link and not helping plz let me know, and wish you can send what sites you have tried so far,

passing means that to send the parameter the method would use in its calculation, sending them when you call the method,

hope this helps, good luck

knowledgelover
Junior Poster in Training
86 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Thanks everyone. I will look over the link and see if it helps.

girlinwayside
Newbie Poster
8 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 
I dont understand what it means by "passing"

'passing' here is about the same as in sports: one guy has the ball, he 'passes' it to another guy, now that other guy has controle over it.

// class that uses an object or class
Sports.showPass("this ball");

// other class -> Sports.java
public void showPass(String pass){
// the String-object 'pass' is passed on to the method
System.out.println("the first player passed " + pass);
}
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

'passing' here is about the same as in sports: one guy has the ball, he 'passes' it to another guy, now that other guy has controle over it.

// class that uses an object or class
Sports.showPass("this ball");

// other class -> Sports.java
public void showPass(String pass){
// the String-object 'pass' is passed on to the method
System.out.println("the first player passed " + pass);
}


Thanks! Those are terms I can understand.. LOL I will be working on this all day today - I have three assignments and an application test all due today! EEEKKK! I have been reading the same chapter in my textbook since Sunday trying to understand this stuff.

girlinwayside
Newbie Poster
8 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Well, this is what I have at this point and its loaded with errors.. I changed my number of eggs to 13 hoping it would make it easier for me to code the computation

public class Eggs

{
public static void main(String[] args)
{
numberOfEggs();
}

public static void numberOfEggs;

System.out.println ("13 eggs are one full dozen + remaining")

// Kelly Bowden - Assignment # 3, Chapter 3, February 3, 2009
}
}


public class Test

{
public static void main(String[] args)
{
System.out.println("Calling method from another class");
Eggs.numberOfEggs();
// Kelly Bowden - Assignment # 3, Chapter 3, February 3, 2009
}
}

public class Eggs2

{

public static void main(String[] args)
{
int dozen = 12;
int eggs = 13;
numberOfEggs();
eggs - dozen = remaining;

}

public static void numberOfEggs;

System.out.println ("13 eggs are one full dozen + remaining")

// Kelly Bowden - Assignment # 3, Chapter 3, February 3, 2009
}
}

girlinwayside
Newbie Poster
8 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

public class Eggs2 { public static void main(String[] args) { int dozen = 12; int eggs = 13; numberOfEggs(); eggs - dozen = remaining; }

public static void numberOfEggs;

System.out.println ("13 eggs are one full dozen + remaining")

// Kelly Bowden - Assignment # 3, Chapter 3, February 3, 2009 } }


I'm not really sure what you're trying to do in here, but there are indeed a number of serious errors in here.

public class Eggs2 
{
    public static void main(String[] args)  {
	int dozen = 12;
	int eggs = 13;	
//        numberOfEggs();
//	eggs - dozen = remaining;
       int remaining = eggs - dozen;
       numberOfEggs(remaining);
    }

//public static void numberOfEggs;
public static void numberOfEggs(int remaining){ 

	//System.out.println ("13 eggs are one full dozen + remaining")
	System.out.println("13 eggs are one full dozen + remaining");
      // what I think you want to do here is:
       System.out.println("13 eggs are one full dozen + " + remaining);

	// Kelly Bowden - Assignment # 3, Chapter 3, February 3, 2009
        }
}
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

Look at a piece of example code. . you're attempting to use numberOfEggs as if its a method, but you have not declared it w/ a method header & method body.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

Do you have this solved and turned in yet. Are you still stuck?

rapture
Posting Whiz in Training
294 posts since Jul 2007
Reputation Points: 155
Solved Threads: 41
 
try to read in elliot coffman book in java its very simple to understand public class eggs {public static void main(String args []) { int NumberOfEggs =25; System.out.print("Full dozen"+ duzen(NumberOfEggs ) ); } public int duzen( int x) {return x/12; } }

This is how i did mine like that:
import java.util.Scanner;
public class Eggs
{
public static void main(String args [])
{

int eggs;
int numberOfEggs;
int dozen = 12;

Scanner inputDevice = new Scanner(System.in);
System.out.print("Please enter the number of eggs ...");
eggs = inputDevice.nextInt();
System.out.print("Total eggs " + eggs*dozen);

}
}
hope it helps.

djnojoda01
Newbie Poster
1 post since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

so i am trying to figure out a code to use in java and i cant seam to get it right. i am trying to use a simple addition function. i feel so stupid!!!!

agh
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

and what's your point?
you don't show what code it is you 're looking into, you don't say what problems you 're encountering, you're not even taking the time to create a new thread for your questions (if any) ..
not really the most valuable post on this forum

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You