Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CPS 180 Lab Assignment #6: Team Game Scoring Assignment Assigned: 06/02/17 Due:

ID: 3847535 • Letter: C

Question

CPS 180 Lab Assignment #6: Team Game Scoring Assignment Assigned: 06/02/17 Due: 06/09/17 Points: 40 Create a Java program to simulate some 2 team game. Ask the user to input the following information: gN Game Name tIN Team 1 Name t2N Team 2 Name nP of periods (quarters, innings, periods) SV-points per score choose one, even if game has multiple scores (i.e. football) SN Score Name pN-Period Name The program should work for any game such as football, baseball, hockey, basketball, soccer, etc. 1. Use appropriate variable names and data types for these inputs. 2. Also create variables to accumulate the scores for each respective team, such as teamiscore, team2Score. 3. Input data for the 7 variables from the user 4. Set up a counter controlled loop to go through the periods from 1. nP. 5. Tally the points for each team, then report the results, along with the winner, or if it were a tie. Create data validation loops for the 2 numeric inputs (range check for 1 through 7). 6. Provide 3 sets of sample output. Store the files in a .zip (not a .7zip or .rar). Here is an example of Sample output: Please Enter Game Name: Football Please Enter Football Team 1 Name: Dolphins Please Enter Football Team 2Name: Chargers What is a score in Football called? Touchdown

Explanation / Answer

package revv;

import java.util.Scanner;

public class Test {

  

  

   public static void main(String[] arhs) throws Exception {

  

       String gN;

       String t1N;

       String t2N;

       int nP;

       int sV;

       int t1S=0;

       int t2S=0;

       String sN;

       String pN;

      

       Scanner sc = new Scanner(System.in);

       System.out.println("Please enter game name :");

       gN = sc.nextLine();

       System.out.println("Please enter " + gN + " team 1 name");

       t1N = sc.nextLine();

      

       System.out.println("Please enter " + gN + " team 2 name");

       t2N = sc.nextLine();

      

       System.out.println("What is a score in " + gN + " called");

       sN = sc.nextLine();

      

       System.out.println("How many points per " + sN + " in " + gN);

       sV = sc.nextInt();

      

       System.out.println("What is a period in " + gN + " called");

       pN = sc.nextLine();

      

       System.out.println("How many " + pN + " in " + gN);

       nP = sc.nextInt();

      

       for(int i=1;i<=nP;i++){

           System.out.println(pN + " #" +i);

           System.out.println("How many "+ sN + " for " + t1N);

           int a = sc.nextInt();

           t1S = t1S +a;

           System.out.println("How many "+ sN + " for " + t2N);

           int b = sc.nextInt();

           t2S = t2S +b;

       }

      

       System.out.println(gN + " Game Results: -------------------------");

       int t1Score = t1S * sV;

       int t2Score = t2S * sV;

       System.out.println(t1N + " scored " + t1S + " " + sN + " for a score of " + t1Score);

       System.out.println(t2N + " scored " + t2S + " " + sN + " for a score of " + t2Score);

       int diff = t1Score - t2Score;

       if(diff > 0)

           System.out.println(t1N + " win by " + diff + " points");

       else if( diff < 0){

           diff = -1* diff;

           System.out.println(t2N + " win by " + diff + " points");

       }

   }

}