Java help math.min / math.max - Page 2 - Overclock.net - An Overclocking Community

Forum Jump: 

Java help math.min / math.max

Reply
 
Thread Tools
post #11 of 14 (permalink) Old 09-22-2010, 11:40 AM - Thread Starter
New to Overclock.net
 
Join Date: Feb 2008
Location: Indiana
Posts: 183
Rep: 5 (Unique: 5)
booyah! i figured it out. Thanks guys. I'll post the final code.
.dp-BarackObama is offline  
Sponsored Links
Advertisement
 
post #12 of 14 (permalink) Old 09-22-2010, 11:52 AM - Thread Starter
New to Overclock.net
 
Join Date: Feb 2008
Location: Indiana
Posts: 183
Rep: 5 (Unique: 5)
Final Project Code

Code:
import java.util.Scanner;

public class QuarterbackEfficiencyRating {


/**
 * George Turkette
 * CS160-01 Fall 2010
 * Project 1: NFL Quarterback Efficiency Rating
 * 
 * Description: This program takes in five variables: attempts, completions, yards, touchdowns, and interceptions and 
 * determines a quarterbacks efficiency rating (QBER). 
 */
public static void main(String[] args) 
{

final double MIN_RATING = 0.0; // Min rating value
final double MAX_RATING = 2.375; // Max rating value

// Variables
String name; //The name of the quarterback
int attempts; // Number of attempts
int completions; // Number of completions
double yards; // Total Yards
int touchdowns; // Touchdowns
int interceptions; // Interceptions

// Declare and instantiate Scanner object
Scanner keyboard = new Scanner(System.in);

// Prompt user to input the name quarterback
System.out.print("Enter quarteback's name>");
name = keyboard.nextLine();

// Prompt user to input attempts
System.out.print("Enter number of attempts>");
attempts = keyboard.nextInt();

// Prompt user to input completions
System.out.print("Enter number of completions>");
completions = keyboard.nextInt();

//Prompt user to input total yards
System.out.print("Enter total yards>");
yards = keyboard.nextInt();

//Prompt user to input touchdowns
System.out.print("Enter number of touchtowns>");
touchdowns = keyboard.nextInt();

//Prompt user to input number of interceptions
System.out.print("Enter number of interceptions>");
interceptions = keyboard.nextInt();

//Calculation variables
double comp; //percentage of completions per attempt
double yds; // average yards gained per attempt
double tds; //percentage of touchdown passes per attempt
double ints; //percentages of interceptions per attempt
double QBER; //Quarterback Efficiency rating

//Calculates COMP
comp = 0.05 * (((100.0 * completions) / attempts) - 30);
comp = Math.min(comp, MAX_RATING); // If comp > MAX_RATING then set comp to MAX_RATING
comp = Math.max(comp, MIN_RATING); // if comp < MIN_RATING then set comp to MIN_RATING

//Calculates yds
yds = 0.25 * ((yards / attempts) - 3.0);
yds = Math.min(yds, MAX_RATING); // If yds > MAX_RATING then set yds to MAX_RATING
yds = Math.max(yds, MIN_RATING); // if yds < MIN_RATING then set yds to MIN_RATING

//Calculates tds
tds = 0.2 * (100.0 * touchdowns / attempts);
tds = Math.min(tds, MAX_RATING); // If tds > MAX_RATING then set yds to MAX_RATING

//Calculates ints
ints = 2.375 - 0.25 * (100.0 * interceptions / attempts);
ints = Math.min(ints, MAX_RATING); // If ints > MAX_RATING then set yds to MAX_RATING

//Calculates QBER
QBER = 100 * (comp + yds + tds + ints) / 6;

//Display the QBER
System.out.println("\
\
QBER Ananlysis for " + name
+ "\
\
COMP = " + comp
+ "\
YDS = " + yds
+ "\
TDS = " + tds
+ "\
INTS = " + ints
+ "\
\
QBER = " + QBER);


}
}
.dp-BarackObama is offline  
post #13 of 14 (permalink) Old 09-22-2010, 11:57 AM
New to Overclock.net
 
tindolos's Avatar
 
Join Date: Nov 2007
Posts: 1,349
Rep: 93 (Unique: 81)
Quote:
Originally Posted by .dp-BarackObama View Post
Final Project Code

Code:
import java.util.Scanner;

public class QuarterbackEfficiencyRating {


/**
 * George Turkette
 * CS160-01 Fall 2010
 * Project 1: NFL Quarterback Efficiency Rating
 * 
 * Description: This program takes in five variables: attempts, completions, yards, touchdowns, and interceptions and 
 * determines a quarterbacks efficiency rating (QBER). 
 */
public static void main(String[] args) 
{

final double MIN_RATING = 0.0; // Min rating value
final double MAX_RATING = 2.375; // Max rating value

// Variables
String name; //The name of the quarterback
int attempts; // Number of attempts
int completions; // Number of completions
double yards; // Total Yards
int touchdowns; // Touchdowns
int interceptions; // Interceptions

// Declare and instantiate Scanner object
Scanner keyboard = new Scanner(System.in);

// Prompt user to input the name quarterback
System.out.print("Enter quarteback's name>");
name = keyboard.nextLine();

// Prompt user to input attempts
System.out.print("Enter number of attempts>");
attempts = keyboard.nextInt();

// Prompt user to input completions
System.out.print("Enter number of completions>");
completions = keyboard.nextInt();

//Prompt user to input total yards
System.out.print("Enter total yards>");
yards = keyboard.nextInt();

//Prompt user to input touchdowns
System.out.print("Enter number of touchtowns>");
touchdowns = keyboard.nextInt();

//Prompt user to input number of interceptions
System.out.print("Enter number of interceptions>");
interceptions = keyboard.nextInt();

//Calculation variables
double comp; //percentage of completions per attempt
double yds; // average yards gained per attempt
double tds; //percentage of touchdown passes per attempt
double ints; //percentages of interceptions per attempt
double QBER; //Quarterback Efficiency rating

//Calculates COMP
comp = 0.05 * (((100.0 * completions) / attempts) - 30);
comp = Math.min(comp, MAX_RATING); // If comp > MAX_RATING then set comp to MAX_RATING
comp = Math.max(comp, MIN_RATING); // if comp < MIN_RATING then set comp to MIN_RATING

//Calculates yds
yds = 0.25 * ((yards / attempts) - 3.0);
yds = Math.min(yds, MAX_RATING); // If yds > MAX_RATING then set yds to MAX_RATING
yds = Math.max(yds, MIN_RATING); // if yds < MIN_RATING then set yds to MIN_RATING

//Calculates tds
tds = 0.2 * (100.0 * touchdowns / attempts);
tds = Math.min(tds, MAX_RATING); // If tds > MAX_RATING then set yds to MAX_RATING

//Calculates ints
ints = 2.375 - 0.25 * (100.0 * interceptions / attempts);
ints = Math.min(ints, MAX_RATING); // If ints > MAX_RATING then set yds to MAX_RATING

//Calculates QBER
QBER = 100 * (comp + yds + tds + ints) / 6;

//Display the QBER
System.out.println("\
\
QBER Ananlysis for " + name
+ "\
\
COMP = " + comp
+ "\
YDS = " + yds
+ "\
TDS = " + tds
+ "\
INTS = " + ints
+ "\
\
QBER = " + QBER);


}
}


Grats! Now just implement a recursive function for your min/max needs and earn some brownie points


Current Rig
(12 items)
CPU
i7 7700K @ 5.0 Ghz
Motherboard
MSI Z720 Gaming Pro Carbon
GPU
Gigabyte GTX 1070 8GB WINDFORCE OC
RAM
G.SKILL TridentZ RGB DDR4 16 GB @ 3200
Hard Drive
Samsung 970 Pro NVMe M.2 512GB
Hard Drive
Samsung 840 EVO SSD 250GB
Power Supply
Corsair RM850i
Cooling
Noctua NH-D15S
Case
Fractal Define XL
Operating System
Windows 10
Keyboard
SteelSeries Apex M750
Mouse
SteelSeries Rival 310
▲ hide details ▲
tindolos is offline  
Sponsored Links
Advertisement
 
post #14 of 14 (permalink) Old 09-22-2010, 11:57 AM
New to Overclock.net
 
ShifterMSK's Avatar
 
Join Date: Feb 2010
Location: Morgantown, W.V.
Posts: 54
Rep: 4 (Unique: 4)
Yeah, you used double like I said.

ShifterMSK is offline  
Reply

Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the Overclock.net - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may post new threads
You may 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 Off
Pingbacks are Off
Refbacks are Off