Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Java Help

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-21-2007, 02:25 AM
kadriatil kadriatil is offline
Newbie
 
Join Date: Mar 2007
Posts: 2
Rep Power: 0
kadriatil is on a distinguished road
Default can you solve this problem with java

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-21-2007, 01:11 PM
icepack's Avatar   
icepack icepack is offline
Programmer
 
Join Date: Jul 2006
Location: North Carolina
Posts: 115
Rep Power: 9
icepack is on a distinguished road
Send a message via AIM to icepack
Default

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"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-21-2007, 01:46 PM
kadriatil kadriatil is offline
Newbie
 
Join Date: Mar 2007
Posts: 2
Rep Power: 0
kadriatil is on a distinguished road
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-21-2007, 03:01 PM
icepack's Avatar   
icepack icepack is offline
Programmer
 
Join Date: Jul 2006
Location: North Carolina
Posts: 115
Rep Power: 9
icepack is on a distinguished road
Send a message via AIM to icepack
Default

well i wish my father did stuff like this!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-21-2007, 09:12 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,470
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Ideal situation for an LRStruct
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-17-2007, 11:37 AM
Lawtonfogle's Avatar   
Lawtonfogle Lawtonfogle is offline
Newbie
 
Join Date: Apr 2007
Posts: 8
Rep Power: 0
Lawtonfogle is on a distinguished road
Default

I read this problem so that an actual iterator isn't needed. A simple while loop can be used.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-29-2007, 09:17 AM
oubless oubless is offline
Newbie
 
Join Date: May 2007
Posts: 22
Rep Power: 6
oubless is on a distinguished road
Default

Quote:
Originally Posted by kadriatil View Post
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
I guess you have experience with C/C++

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 );
  }
...
}
Hope this helps...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT -5. The time now is 12:02 AM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads