All pastes #910336 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-02-19 21:46 UTC
rendered paste body
//********************************************************************
//  WinPercentage.java       Author: Saiful Islam
//
//  Finds the win percentage of a certain team.
//********************************************************************

import java.util.*;

import java.text.DecimalFormat;

public class WinPercentage
{
	public static void main( String[] args )
	{
		//Object Reference Variable Declarations
		String teamName;
		double gamesWon, gamesLost, totalGames, gamesWinPercentage;

		//Creates a decimal format for the win percentage
		DecimalFormat decimalFormat = new DecimalFormat ("##0.00");

		//Creates a new Scanner object
		Scanner input = new Scanner(System.in);

		System.out.print ("Enter the team name: ");
		teamName = input.nextLine();

		System.out.print ("Enter the number of games won: ");
		gamesWon = input.nextDouble();

		System.out.print ("Enter the number of the games lost: ");
		gamesLost = input.nextDouble();

		totalGames = gamesWon + gamesLost;

		gamesWinPercentage = (gamesWon / totalGames) * 100;

		//Displays the results
		System.out.println (""); //Displays an empty line

		//Displays the team name and how many games they have played
		System.out.println ("The team " + teamName + " played a total of "
							+ totalGames + " game(s)");

		//Displays how many games the team won and lost
		System.out.println ("They won " + gamesWon + "game(s) and lost "
							+ gamesLost + " game(s)");

		//Displays the team's win percentage
		System.out.println ("Their win percentage is "
							+ decimalFormat.format(gamesWinPercentage) + " %");
	}
}