• 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

Array

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello!
i'm new here, and boy am i glad to have found u guys!!
i've been going crazy trying to do this homework that was assigned to me... here's the link!

can someone help me out, pwetty pweez with a cherry on top

p.s. i've visited a whole bunch of forums before, but i must admit, u guys have the best sense of humor.. i especially enjoyed reading the rules prior to registration: "be nice." lol awesome!
[ April 26, 2005: Message edited by: Esraa Halim ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

We don't like to do people's work for them, but we do like to help people learn.

This is a simple sort of program, with three parts:

1) Collect some input
2) Compute some numbers
3) Print a report

Tackle each part separately.

So: go get started. Come back to this thread and show us what you have when you get stuck, and ask for more specific advice.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you might want to rename your thread topic. Posts with Help as their title usually don't get much help.

It is kind of along our be nice rule. Most people will look at all the titles and go into the threads that they know what they are going to be about, and if they can help on that topic. With "Help" they will have no clue what the thread is about and just ignore it.

Good Luck in your project.

Mark
 
EgySnob87
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well thanks guys

and ernest.. i do have a specific question! where do i start?

i know i need an array (obviously lol), but how do i get the program to search for numbers less than and more than the average? do i use sequentialSearch() for that?
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Esraa Halim:
where do i start?

At the beginning, of course! Does your program read in the non-negative integer n? Does it create an array of size n? Does it read in n integers and store them into the array?

If not, well, that's where you should be focusing your attention. If your program does all that, then you've already started and gotten to the middle!
 
EgySnob87
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lol ok, well i guess i need help with the middle then!

how do i get the program to output numbers less than, equal to, and more than the average?
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first, you will likely need to know what the average is. then, you search through the array of numbers, comparing them each in turn to the average, and decide how to print them. might that work?
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Things you'll need to know or figure out how to do for stage two:
  • iterate through an array, one at a time
  • calculate an average from an array of numbers
  • print a number to the screen (called the console)

  • Which of these has you stumped? If you're not sure how to proceed, post your thoughts and any code attempts you've made.
     
    EgySnob87
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    WOOHOO! i actually got it done today, and all on my own .. i went and talked to my professor, and she thinks i was just complicating things too much (something i'm very good at!) ... and here's the code, if anyone's interested or has any suggestions (since my exam will be on the 9th of may):




    thanks to all who tried to help
    [ April 27, 2005: Message edited by: Esraa Halim ]
     
    Ranch Hand
    Posts: 76
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Reasonable enough code, for the most part. Strictly speaking, you're not calculating the average, as the number you call the average is rounded down to an int; you want a float or a double for the average. (The average of 0 and 1 is 0.5, but your code would give the average as 0.) You don't need the last loop, as the number of ints greater than the average is n - the number of ints equal to the average - the number of ints less than the average. Also, you can calculate the sum while the user is entering the integers, so you can drop that loop as well.

    Never saw the Scanner class before, it's a cool feature of 1.5. Don't use it as a crutch--if you're going to do any real programming, you'll need to understand how I/O works in Java.
     
    David Harkness
    Ranch Hand
    Posts: 1646
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Looks good. It was pretty clear from your initial posts that you suffer from complexititis, but being aware of it is 90%. Here's some style advice since the code works. Mind you some of the latter ones are not hard and fast but rather things I follow and have noticed.

    In Java, classes and interfaces are named using CamelCase with an initial capital letter whereas non-final variables and methods get camelCase with an initial lowercase letter. Final variables (constants) get ALL_CAPS_WITH_UNDERSCORE_SEPERATORS.

    Having a constructor is misleading since your class is not designed to be constructed. I'd remove the "public finallyArrays() { }" altogether.

    Your indentation style can be confusing. There are a few traditional styles that are generally accepted, but the one you use is actually misleading. Here are the three styles I've seen, first being most common.And now here's yours:Notice that the close brace for the for block lines up with the "if" of the inner block. That's why it's misleading. All of the standard styles put the close brace in the same place: the column of the first character of the line that started the block.

    I recommend choosing one of the other styles not because yours is different but because it will confuse people used to the standard styles. Of course, if this is a mandate from your professor, I'd try very hard to convince him to change.

    Tip: You can use System.out.print() instead of println() so that the cursor stays on the same line right after the prompt.Now I'm reaching. Every time I see an increment used in a for loop, it's always post-increment. It makes no difference here, but I notice that using pre-increment catches my eye as being "off" and makes it harder to skim the code since it isn't what I expect to see.versusOh yeah, it's also easier to read (I find) when you put spaces around operators, but that has more to do with my vision than anything else. Others may not even notice.

    Anyway, good job on your assignment, and I hope my nitpicking comes across as constructive.
     
    EgySnob87
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Adam and David, thank u guys sooo so much! i will take all of ur "nitpicking" into consideration for the exam lol... and David, for some reason my code here does not look as neat as it did in NetBeans, so i apologize for any inconvenience but it wasn't entirely my fault i promise :roll:

    thanks once more!
     
    David Harkness
    Ranch Hand
    Posts: 1646
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    No worries on my end. When I look at other people's code, I paste it into my editor and select Text : Format Source so it matches my style. I'd bet NetBeans has a formatting command, too.

    You might want to check how it's setup to handle indentation: tabs or spaces and how many characters per tab. Note, however, that the only agreement on indentation is that a) there is no agreement and b) just be consistent.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic