• Post Reply Bookmark Topic Watch Topic
  • New Topic

New to Java and stuck on an assignment  RSS feed

 
Nabih Abushaban
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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?

 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: Look at lines 32 - 35.
 
Nabih Abushaban
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
would it be something like this?
for code 1?

int maxPerformer = ithPersonName
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • 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: 56600
172
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
would the correct code be

totalSales = 50000+ rand.Int(200000);

??
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
should it states 150000 instead of 200000?
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
After reading the API.. I would think that I could remove the rand.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nabih Abushaban wrote:After reading the API.. I would think that I could remove the rand.
Why?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!