Objects by Design Forums Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home  
Objects by Design Forums : Powered by vBulletin version 2.3.5 Objects by Design Forums > Main Forums > UML Questions > Java to UML
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
the only man
Junior Member

Registered: Dec 2005
Location:
Posts: 2

Java to UML

how do i convert this java code to uml???

code:
public class Tournament { static Course course; public static final int NUMPLAYERS = 2; static Player [] players; public static void main(String[] args) { String coursename; int length; //Code here to enter coursename and //length interactively course = new Course(coursename, length); players = new Player[NUMPLAYERS]; for (int i = 0; i < players.length; ++i) { String playername; int hand; //Code here to enter playername and // hand (the player's handicap) interactively players[i] = new Player(playername, hand, course); } for (int i = 0; i < course.getLength(); ++i) { for (int j = 0; j < players.length; ++j) { players[j].playHole(i); } } for (int i = 0; i < players.length; ++i) { players[i].print(); } int minScore = Integer.MAX_VALUE; int pos = 0; for (int i=0; i<players.length; ++i) { if (players[i].getFinalScore() < minScore) pos = i; } System.out.println("The winner is "+players[pos].getName()); } } // Tournament public class Course { private String name; private Hole [] course; public Course(String n, int hnum) { name = n; course = new Hole [hnum]; Stream in = new Stream(System.in); for (int i = 0; i < course.length; ++i) { int tmp; //Code here to enter tmp (the par for the current // hole) interactively course[i] = new Hole (tmp); } } public String getName () { return name; } public int getLength () { return course.length; } public int getPar(int i) { return course[i].getPar(); } } // Course public class Player { private String name; private int handicap; private ScoreCard scard; private static Random r = new Random(); public Player(String n, int hand, Course c) { name = n; handicap = hand; scard = new ScoreCard(c); } public String getName () { return name; } public void playHole (int num) { int score = r.nextInt(7) + 1; scard.setScore(num, score); } public void print () { System.out.println("I'm " + name); scard.print(); System.out.println("My handicap is "+handicap+ ", so my final score is "+getFinalScore()); } public int getFinalScore () { return scard.getTotal() - handicap; } } // Player public class ScoreCard { private HoleScore [] scores; private Course course; public ScoreCard(Course c) { course = c; scores = new HoleScore [course.getLength()]; } public void setScore (int i, int s) { scores[i] = new HoleScore(s); } public int getScore (int h) { return scores[h-1].getScore(); } public int getTotal () { int total = 0; for (int i=0; i<course.getLength(); ++i) total += scores[i].getScore(); return total; } public void print () { System.out.println("Hole\tPar\tScore\t+/-Par"); int courseTotal = 0; int gross = 0; int againstPar = 0; for (int i = 0; i < course.getLength(); i++) { int iPar = course.getPar(i); int iScore = getScore(i+1); int iplusminus = getScore(i+1) - course.getPar(i); courseTotal = courseTotal + iPar; gross = gross + iScore; againstPar = againstPar + iplusminus; System.out.print(i+1 + "\t"); System.out.print(iPar + "\t"); System.out.print(iScore + "\t"); System.out.print(iplusminus); System.out.println(); } System.out.print("Total\t"); System.out.print(courseTotal + "\t"); System.out.print(gross + "\t"); System.out.println(againstPar + "\t"); } } // ScoreCard public class HoleScore { private int score; public HoleScore(int s) { score = s; } public int getScore () { return score; } } // HoleScore

__________________
The Great One!!!

Report this post to a moderator | IP: Logged

Old Post 12-11-2005 04:41 PM
the only man is offline Click Here to See the Profile for the only man Click here to Send the only man a Private Message Find more posts by the only man Add the only man to your buddy list Edit/Delete Message Reply w/Quote
SZ
Administrator

Registered: Apr 2001
Location: New York
Posts: 492

Most professional UML tools provide a reverse-engineering capability to convert Java code into high-quality UML class diagrams. These diagrams can then be exported to JPG or SVG formats.

For a list of UML tools, many of which are free, see the OBD list of UML tools.

Let's see your results!

Report this post to a moderator | IP: Logged

Old Post 12-14-2005 04:35 AM
SZ is offline Click Here to See the Profile for SZ Click here to Send SZ a Private Message Visit SZ's homepage! Find more posts by SZ Add SZ to your buddy list Edit/Delete Message Reply w/Quote
bruno_pages
Junior Member

Registered: May 2005
Location: France
Posts: 19

I propose you to use Bouml, few seconds are enough to reverse your code and create the following diagram. Note : a drawing setting allows to choose the language used to indicate the attributes and operation, here I had choose Java rather than UML to help you to see the link with your example.
http://bouml.free.fr/tournament.png

__________________
Bruno Pages

author of BOUML (http://bouml.free.fr)

joint author of XCORAL (http://xcoral.free.fr)

Report this post to a moderator | IP: Logged

Old Post 12-17-2005 09:55 AM
bruno_pages is offline Click Here to See the Profile for bruno_pages Click here to Send bruno_pages a Private Message Visit bruno_pages's homepage! Find more posts by bruno_pages Add bruno_pages to your buddy list Edit/Delete Message Reply w/Quote
the only man
Junior Member

Registered: Dec 2005
Location:
Posts: 2

Hex game

i need a computer player in HEX game which is strong and unbeatable. here is a sample code but is not that good.

there are few type of comp player:-
Random
Blocker
Defensive
etc

i need one that is strong.

this is the rule but i cant implement into java.


quote:
For play on a nx(n+1) board, the second player, playing the shorter direction, can always win by playing a mirror image move...




code:
public class ComputerPlayer007 implements ComputerPlayer { private final String name="Next (MH)"; public ComputerPlayer007() { } public String getName(){ return name; } public IntPair getMove(Board b,int c){ for (int i=0;i<b.getSize();++i) { for (int j=0;j<b.getSize();++j) { if (b.value(i,j)==Stone.WHITE) return (new IntPair(i,j)); } } return null; }; } //

__________________
The Great One!!!

Report this post to a moderator | IP: Logged

Old Post 12-17-2005 04:43 PM
the only man is offline Click Here to See the Profile for the only man Click here to Send the only man a Private Message Find more posts by the only man Add the only man to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 01:34 PM. Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 

< Contact Us - Objects by Design >

Powered by: vBulletin Version 2.3.5
Copyright ©2000 - 2018, Jelsoft Enterprises Limited.
Copyright 1999-2005, Objects by Design, Inc.