218k views
5 votes
Main topics: Basic Java program

Programmatic output
Arithmetic Expressions
User input
Program Specification:
Write a Java program that calculates and outputs a baseball pitcher’s ERA in a reasonable report format. "ERA" is an acronym for "earned run average" and is computed using the following equation: number of earned runs multiplied by 9 and divided by number of innings pitched Your program must do the following: • Prompt the user for the first and last name of the pitcher and store them in two variables of type String • Prompt the user for the pitcher’s number of earned runs and store it in a variable of type int • Prompt the user for the pitcher’s number of innings pitched and store it in a variable of type int • Compute and output the pitcher’s ERA, which should be a (double) floating point number Sample run(s): Pitcher’s first name: Josh Pitcher’s last name: Hader Number of earned runs: 22 Number of innings pitched: 81 Josh Hader has an ERA of 2.4444444444444446

User Schlicht
by
7.4k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

import java.util.Scanner;

public class pitcherValues {

public static void main(String[] args) {

String firstName, lastName;

int earnedRuns, inningsPitched;

double ERA;

Scanner in = new Scanner(System.in);

System.out.println("Pitchers First Name is?");

firstName = in.nextLine();

System.out.println("Pitchers Last Name is?");

lastName = in.nextLine();

System.out.println("How many runs did the Pitcher earn?");

earnedRuns = in.nextInt();

System.out.println("How many innings did the Pitcher Pitch?");

inningsPitched = in.nextInt();

ERA = (earnedRuns * 9) / inningsPitched;

System.out.println(firstName + " " + lastName + " has an ERA of " + ERA);

}

}

User Sandy Gettings
by
7.0k points