0% found this document useful (0 votes)
24 views5 pages

CIS 1115 Assignment 2 Solved Google Docs

assignment 2 solved

Uploaded by

Talha Tahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

CIS 1115 Assignment 2 Solved Google Docs

assignment 2 solved

Uploaded by

Talha Tahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Project Code for BaseballStats Project:

Here is the code for the project:

package BaseballStats;

// This is a Java program to compute baseball statistics

// Author: [Mohammad Hakim] on [3/13/2023]

import java.util.Scanner; // Import the Scanner class for user input

public class BaseballStats {

public static void main(String[] args) {

Scanner input = new Scanner(System.in); // Create a new Scanner object for user input

System.out.println("Welcome to the Baseball Statistics Program by [Mohammad Hakim] on [3/13/2023]!"); //


Print welcome message and your name

int numTeams = 0; // Initialize the number of teams to zero

while (true) { // Loop indefinitely

// Read in the team's id number and won/loss record

System.out.print("Enter team id number: ");

int id = input.nextInt();

System.out.print("Enter team Numer of Wins: ");

int wins = input.nextInt();

System.out.print("Enter team number of Losses: ");

int losses = input.nextInt();

System.out.println(id + " " + wins + " " + losses);

// Compute the total number of games played and games remaining

int totalGames = wins + losses;

int remainingGames = 25 - totalGames;

// Check if the season is finished and print appropriate message


if (totalGames == 25) {

System.out.println("The season is finished.");

} else {

System.out.println("Total number of games played: " + totalGames);

System.out.println("Number of games remaining: " + remainingGames);

// Compute the team's winning average and print it

double winningAverage = (double) wins / totalGames;

System.out.printf("The winning average is: %.4f\n", winningAverage);

// Compare number of games remaining to number won and number lost and print appropriate messages

if (remainingGames >= wins) {

System.out.println("Number of games remaining is greater than or equal to number won.");

} else {

System.out.println("Number of games remaining is not greater than number won.");

if (remainingGames > losses) {

System.out.println("Number of games remaining is greater than number lost.");

} else {

System.out.println("Number of games remaining is not greater than or equal to number lost.");

// Increment the number of teams

numTeams++;

// Ask if the user wants to enter another team's data

System.out.print("Enter another team's data? (y/n): ");

String answer = input.next();

if (answer.equals("n")) {

break; // Exit the loop if the user enters 'n'


}

// Print the total number of teams processed

System.out.println("The total number of teams is: " + numTeams);

Project Code pictures for BaseballStats Project:


Here is the pictures of the project code:
Project Code Output pictures for BaseballStats Project:
Here is the code ouput picture attached in which the output of the given code can clearly be seen:

You might also like