AP JAVA cricket program, Assignments of Computer science

JAVA code for a cricket program

Typology: Assignments

2022/2023

Uploaded on 01/07/2023

Spyroqz
Spyroqz 🇺🇸

6 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Input:
import java.util.Scanner;
public class cricket {
// code to implement method playerandRuns
public static void playerandRuns(int[] score, String[] players) {
for (int i = 0; i < players.length; i++) {
System.out.println("Player: " + players[i] + "\t" + "\t" + "Runs: " + score[i]);
}
}
// code to implement method teamTotal
public static void teamTotal(int[] runs) {
int sum = 0;
for (int i = 0; i < runs.length; i++) {
sum = sum + runs[i];
}
System.out.println(sum);
}
// code to implement method lowScore
public static void lowScore(String[] players, int[] score) {
int lowest = 999;
int index = 0;
for (int i = 0; i < score.length; i++) {
if (score[i] <= lowest) {
lowest = score[i];
index = i;
}
}
System.out.println("Score: " + lowest + "\t" + "Players: " + players[index]);
}
// code to implement method highScore
public static void highScore(String[] players, int[] runs) {
int highest = 0;
int highIndex = 0;
for (int i = 0; i < runs.length; i++) {
if (runs[i] >= highest) {
pf3

Partial preview of the text

Download AP JAVA cricket program and more Assignments Computer science in PDF only on Docsity!

Input: import java.util.Scanner; public class cricket { // code to implement method playerandRuns public static void playerandRuns(int[] score, String[] players) { for (int i = 0; i < players.length; i++) { System.out.println("Player: " + players[i] + "\t" + "\t" + "Runs: " + score[i]); } } // code to implement method teamTotal public static void teamTotal(int[] runs) { int sum = 0; for (int i = 0; i < runs.length; i++) { sum = sum + runs[i]; } System.out.println(sum); } // code to implement method lowScore public static void lowScore(String[] players, int[] score) { int lowest = 999; int index = 0; for (int i = 0; i < score.length; i++) { if (score[i] <= lowest) { lowest = score[i]; index = i; } } System.out.println("Score: " + lowest + "\t" + "Players: " + players[index]); } // code to implement method highScore public static void highScore(String[] players, int[] runs) { int highest = 0; int highIndex = 0; for (int i = 0; i < runs.length; i++) { if (runs[i] >= highest) {

highest = runs[i]; highIndex = i; } } System.out.println(highest + players[highIndex]); } // code to implement method secondhighScore public static int Menu() { // Scanner keyboard = new Scanner(System.in); // complete the menu method // System.out.println(); // return (keyboard.nextInt()); Scanner keyboard = new Scanner(System.in); System.out.println("Enter a Number"); int menuOption = keyboard.nextInt(); keyboard.close(); return menuOption; } public static void endOfProcessing() { System.out.println("\n \t End of Processing \n"); } public static void main(String[] args) { //declare two one dimensional arrays called players and score that store the data shown in the assignment. String[] players = { "Larry Cummings", "Bill Hassel", "Simon Williams", "Don Worrell", "Darrian Weeks", "Neal Wolcott", "Brian Lara", "Anthony Ambrose", "Bernard Cummings", "Dennis Young", "Kamal Tandukar" }; int[] scores = { 54, 93, 26, 12, 85, 77, 127, 68, 51, 98, 37 }; int choice = Menu(); switch (choice) { case 1: {// call the method to perform playerandRuns playerandRuns(scores, players); break; }