File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Hi Guys...It's been a while, but I surely need some help..
I'm trying to write this program that has arrays in it, where I can input a employee's hours in, and then show the results on the screen...
Here's a sample of what I have so far...

public void setHours( ) //This is just a stub. Stub...not done yet.
{

{
System.out.println("Please enter hours worked by the employees.");
System.out.println("EMPLOYEE 1");
System.out.println("Monday.");
monday = SavitchIn.readLineInt();
System.out.println("Tuesday.");
tuesday = SavitchIn.readLineInt();
System.out.println("Wednesday.");
wednesday = SavitchIn.readLineInt();
System.out.println("Thursday.");
thursday = SavitchIn.readLineInt();
System.out.println("Friday.");
friday = SavitchIn.readLineInt();

And I have more for the other two employees...how do I get the stuff to show up on the screen??
It needs to be something like...
Employee 1
Monday 8
Tuesday 5
Wednesday 4
Thursday 2
Friday 8

Total 27
And so on for the other employees..I'm lost...as usual..any help would be greatly appreciated!!!


) ) ) )
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
Rose,

It would seem that you need two arrays here. One static final for weekdays, and the other a regular (hopefully private) instance variable for the hours.

First you must instantiate the array with the keyword new, then populate the array.

Try it, it's really not that hard. Here's what I do when I have a question. I already have Google on my browser menu bar. I type "Java Array" in, then look for an appropriate snippet of code.

By the way, you really only need one print statement. Here's why: if you have an array, printing with a loop is a piece of cake. You loop through weekDay[0] to weekDay[n] and print using a for or while loop. More efficient!

Here's a deal, you figure the array part out, I'll write the output loop for you!

I'd rather teach you to fish, then give you a fish! Tomorrow you may need another collection object!

Hope this helps!
[ January 26, 2005: Message edited by: Marcus Laubli ]

Marcus L´┐Żubli, SCJP 1.4, CLP 5.0, SCWCD 1.4 (preparing)
Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Marcus,

Thanks for teaching me to fish ahhahahaahha....thank you so much..I'll see what I can do and let ya know. I just get so clueless sometimes when it comes to programming. And I do realize now, I didn't need all those system out statements. Duh, on my part for sure. )
Thanks for your help!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays