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
can you solve this problem with java
Started by kadriatil, Mar 20 2007 10:25 PM
6 replies to this topic
#1
Posted 20 March 2007 - 10:25 PM
|
|
|
#2
Posted 21 March 2007 - 09:11 AM
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"
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"
#3
Posted 21 March 2007 - 09:46 AM
thanks ice pack.. it not a home work it just a question that my father asked me. I dont know java so i cant do it. He is teasing me all the time. lol
#4
Posted 21 March 2007 - 11:01 AM
well i wish my father did stuff like this!
#5
Posted 21 March 2007 - 05:12 PM
Ideal situation for an LRStruct :)
#6
Posted 17 April 2007 - 07:37 AM
I read this problem so that an actual iterator isn't needed. A simple while loop can be used.
#7
Posted 29 May 2007 - 05:17 AM
kadriatil said:
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
Structure Prototype = [[Name1, Score1], [Name2, Score2], …]
Example Structure = [[‘Tim’, 98], [‘Tom’, 80], [‘Mike’, 50], [‘Jason’, 25]]
Example Output =
Mike
Jason
89
The following might contain error but it must be easy to fix it:
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 );
}
...
}
Hope this helps...


Sign In
Create Account

Back to top









