Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

New to Java and stuck on an assignment

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I am new to programming and need some help.. I have most of the code completed. I just need some help on the salesteamapp part of my code and it should be completed.
I need to write code that will do the following:

<code1> get team[i]'s name and store in variable ithPersonName
<code2> get team[i]'s totalSales and store in ithPersonSalesAmt
<code3> calculate the difference of totalSales between team[maxPerformer] vs team[i] and store it in ithePersonCatchUpAmt.

What do I need to write to get a teams name and store in the variable?

 
Saloon Keeper
Posts: 9268
78
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Nabih Abushaban
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know it has to do with the above code, I just dont know if I have to do a string or a get
 
Nabih Abushaban
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
would it be something like this?
for code 1?

int maxPerformer = ithPersonName
 
Carey Brown
Saloon Keeper
Posts: 9268
78
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

get team[i]'s name and store in variable ithPersonName


ithPersonName = something with team, and something with name
 
Nabih Abushaban
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Carey, !

On the example above the Team i = Smith.. so in this case would it be correct to write it as

ithPersonName = TeamSmith
 
Marshal
Posts: 75650
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nabih Abushaban wrote:. . .

That is what lots of people think, but it is incorrect. Look closely at this method and work out what the two figures in the comment shou‍ld be. Hint: one of them is correct.
 
Campbell Ritchie
Marshal
Posts: 75650
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nabih Abushaban wrote:. . . would it be correct to write it as

ithPersonName = TeamSmith

No. The compiler will not recognise such a variable.
 
Nabih Abushaban
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
would the correct code be

totalSales = 50000+ rand.Int(200000);

??
 
Campbell Ritchie
Marshal
Posts: 75650
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nabih Abushaban wrote:would the correct code be  . . .

No. I said that one of the figures in the comment, that means right of the //, was wrong.
 
Nabih Abushaban
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
should it states 150000 instead of 200000?
 
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Try something simpler: what is the range of the expression "rand.nextInt(150000)"?

I would suggest reading the API documentation for the method before you answer.
 
Nabih Abushaban
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After reading the API.. I would think that I could remove the rand.
 
Sheriff
Posts: 16930
284
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Programming cannot be done by guessing, which is what you have been doing so far. Frankly, they have been wild guesses and way off the mark.

Programming is like speaking in another language. Like if I wanted to say "The second person" in my native dialect, I would say "Ang ika-duha nga tawo." If I wanted to say "The third person," I would say "Ang ika-tulo nga tawo." The variations would just follow from the fact that we count 2, 3, 4, 5, 6, 7 as "duha, tulo, upat, lima, unom, pito." Given that, can you tell me how we would say "The sixth person" in my dialect?

Similarly, the program you wrote were given is trying to teach you how to say "The Nth whatever" in Java. You are asked to fill in the missing parts by deducing how to say a simple phrase in Java, based on some previous examples, just as I tried to give you some examples of how to say something in my dialect and then asked you to deduce how to say similar phrases.

Read through the program again and see which parts of it represent the idea of "The Nth whatever" and use those as examples. You should then be able to figure out how to say "The I-th Person's name" and other simple phrases, in Java.

Good luck.
 
Campbell Ritchie
Marshal
Posts: 75650
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nabih Abushaban wrote:After reading the API.. I would think that I could remove the rand.

Why?
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic