|
||||||
| Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Write a short program in java (including pseudo-code) to iterate over a structure and print out the names of all users which have a score less than 70. At the end of the structure, also print out the average score of all users who scored 70 or higher. Assume a global function/procedure called print which prints all parameters passed to it and that the structure is called Structure.
Structure Prototype = [[Name1, Score1], [Name2, Score2], …] Example Structure = [[‘Tim’, 98], [‘Tom’, 80], [‘Mike’, 50], [‘Jason’, 25]] Example Output = Mike Jason 89 |
| Sponsored Links |
|
|
|
|||||
|
while I(and hopefully no one else on the site) will not do your homework for you, we can help.
step 1: read about Iterator (Java 2 Platform SE 5.0) from that site it'll be a very simple loop depending if the list "hasNext" |
|
|||
|
Quote:
The following might contain error but it must be easy to fix it: Code:
class Pair{
private String name;
private int score;
Pair(String name, int score){
this.name=name;
this.score=score;
}
public int getScore(){
return score;
}
public String getName(){
return name;
}
}
class ....{
...
public static void main(String args[]){
...
Iterable<Pair> myStructure = .... // initialize your structure.
...
long sum=0;
int count=0;
for( Pair p : myStructure ){
if( p.getScore() < 70 ){
System.out.println( p.getName() );
}
else{
sum+=p.getScore();
count++;
}
}
System.out.println( (double)sum/(double)count );
}
...
}
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MS-SQL deadlock and hang the Java application | reachpradeep | Database & Database Programming | 1 | 03-11-2007 05:20 AM |
| Java Telnet Linux Problem | reachpradeep | Java Help | 0 | 03-05-2007 01:36 PM |
| Java Facts | techni68 | Java Help | 0 | 01-17-2007 02:41 PM |
| John's Java Tutorial Index | John | Java Tutorials | 0 | 01-11-2007 04:05 PM |
| Java Help Files | xXHalfSliceXx | Java Help | 3 | 11-29-2006 12:30 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |