×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create A Program to Create a Baseball Game Statistics in Java Assignment Solution

July 03, 2024
Jessica Miller
Jessica Miller
🇺🇸 United States
Java
Jessica Miller is a seasoned programmer with a master's degree in software engineering from Stanford University. Having completed over 700 Java assignments, Jessica excels in implementing sorting algorithms, multi-dimensional arrays, and efficient array operations. Her deep understanding of complex programming concepts and hands-on experience make her a valuable resource for students seeking high-quality homework help.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Start with basic image processing concepts like color spaces and transformations. Practice simple OpenCV examples to build confidence before tackling complex tasks.
News
In 2024, the release of the 'AsyncIO Toolkit' has made asynchronous programming in Python more efficient. Similarly, 'React Quantum' introduces quantum computing concepts to JavaScript, expanding learning opportunities for students.

Instructions

Objective

To complete a java assignment, write a program to create a baseball game statistics.

Requirements and Specifications

Program-to-create-a-baseball-game-statistics-in-java
Program-to-create-a-baseball-game-statistics-in-java 1.1
Program-to-create-a-baseball-game-statistics-in-java 1.2

Source Code

/* * Heralda Lamarre * Program #1 */ import java.io.File; import java.io.IOException; import java.util.Scanner; public class BaseballStatistics { public static void main(String[] args) throws IOException { System.out.println("Heralda Lamarre"); System.out.println("Program #1"); int GAMES_IN_SEASON = 25; String filename = "baseball.txt"; // reading from console or from file depending on command line argument Scanner scanner = new Scanner(new File(filename)); while(scanner.hasNextLine()) { String[] parts = scanner.nextLine().split("\\s+"); // checking if user wants to exit if (parts.length == 1 && Integer.parseInt(parts[0]) == -1) { // exiting break; } // parsing integers int id = Integer.parseInt(parts[0]); int wins = Integer.parseInt(parts[1]); int losses = Integer.parseInt(parts[2]); int gamesPlayed = wins + losses; if (gamesPlayed > GAMES_IN_SEASON) { System.out.println("Team played more than " + GAMES_IN_SEASON + " games"); continue; } int gamesRemaining = GAMES_IN_SEASON - gamesPlayed; double winningAverage = 0.0; // calculating average only team played some games if (gamesPlayed > 0) { winningAverage = wins * 1.0 / gamesPlayed; } // printing simple stats System.out.println("team " + id); System.out.println(wins + " wins " + losses + " losses"); System.out.println("total number of games played is " + gamesPlayed + " " + gamesRemaining + " games remaining"); System.out.println("the winning average is " + String.format("%.4f", winningAverage)); // making comparisons if (gamesRemaining >= 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 or equal to number won"); } if (gamesRemaining > 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 number lost"); } } } }

Similar Samples

Explore our comprehensive collection of programming homework samples across Java, Python, C++, and more. Each sample showcases our adeptness in solving intricate coding challenges with precision and clarity. Whether you require assistance with algorithms, data structures, or software development projects, our samples exemplify our commitment to delivering top-tier solutions tailored to your academic requirements.