• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic