简体   繁体   中英

Score book using javabean; how do I get overall average?

I have a scorebook that I am writing for a sports club that I need to get an overall value for a final score. There are 5 categories that need to be taken into consideration, three categories have 3 separate parts that need to be scored to return a final value, the other two are scored on their own for an over all score. I am writing a javabean/jsp program to accomplish this task. I works very well except now I need to figure out how to get an overall score and I'm stuck.

Here is my score sheet .jsp

<html>
<body>
<form action="scoresheet.jsp" method="POST">
<h2>
<u><font color="ff3300">RISC Score Book</font></u>
</h2>
<h3>
Please the player's name:
</h3>
<p></p>
<h4>
First Name: <input type="text" name="first" id="first"><br>
Last Name:  <input type="text" name="last" id="last" /><br>
</h4>
<p></p>
<h3>
<u>Please enter the players's bowling scores:</u>
</h3>
<h4>
Game01: <input type="number" name="game01" id="game01"><br>
Game02: <input type="number" name="game02" id="game02"><br>
Game03: <input type="number" name="game03" id="game03"><br>
</h4>
<h3>
<u>Please enter the players's dart scores:</u>
</h3>
<h4>
Dart01: <input type="number" name="dart01" id="dart01"><br>
Dart02: <input type="number" name="dart02" id="dart02"><br>
Dart03: <input type="number" name="dart03" id="dart03"><br>
</h4>
<p></p> 
<h3>
<u>Please enter the player's Quoits scores:</u>
</h3>
<h4>
Quoits01: <input type="number" name="quoits01" id="quoits01"><br>
Quoits02: <input type="number" name="quoits02" id="quoits02"><br>
Quoits03: <input type="number" name="quoits03" id="quoits03"><br>
</h4>
<p></p>
<h3>
<u>Please enter the players's Pong & Golf Scores.</u>
</h3>
<h3>
Pong: <input type="number" name="pong" id="pong"><br>
</h3>
<p></p>
<h3>  
Golf:   <input type="number" name="golf" id="golf"><br>
</h3>
<input type="submit" value="Submit" id='scoreSubmit' />
</form>
</body>
</html>

Here is an example of some of the bean code that I wrote:

public String getGame01() {
            return Game01;
                          }
public void setGame01(String Game01) {
            this.Game01 = Game01;
                                     }
    public String getGame02() {
            return Game02;
                              }
public void setGame02(String Game02) {
            this.Game02 = Game02;
                                     }
        public String getGame03() {
            return Game03;
                              }
public void setGame03(String Game03) {
            this.Game03 = Game03;
                                     }

So all three of the categories that have three parts are written in the bean similar to the above code. The convenience method that I wrote for the above bean to get the average of the three games is this example:

        public double getGameAverage()    {
        String[] games = new String[]{game01, game02, game03};  
                int sum = 0;
                for (String input : games)        {
                sum += Double.parseDouble(input);   
                                                    }
                    return (sum * (10) / 3);
                                        }

So I can get the averages of the first three games(Bowling, Darts and Quoits) in this manner. For golf and pong we are just taking a single game score and incorporating it in to the final score.

Ok, that's the setup....here is my issue:

I need to take the numbers from Bowling, Darts and Golf plus the numbers I get from golf and pong and apply this equation to them:

Value Bowling: 25% of overall average

Value Darts: 20% of overall average

Value Quoits: 20% of overall average

Value Pong: 10% of overall average

Value Bowling: 25% of overall average.

I don't know how to get the return from the two values input by the user (Golf and Pong) and the three values calculated by the bean and apply this equation to them:

{
((Bowl)*(.25))
+
((Darts)*(.20))
+
((Quoits)*(.20))
+
((Pong)*(.20))
+
((Golf)*(.20))
} 
= 100%

Any help would be greatly appreciated. I'm a tad confused on this one and pretty new to java, .jsp and servlets.

Why not use any of the numbers to get the overall score. For instance if Bowl=(25/100)*overAllScore, it means overAllScore=100*Bowl/25

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM