0

This is the instructions

Program converts American football plays into scoring points
Touchdown – 6
Extra point after touchdown – 1
Field goal – 3
Touchback – 2
Program reads play-name and uses “if-statement” to decide how many points to award
Program does calculations in a loop to allow more than one play

Score two teams, home and away
Ex: Please enter a play: touchdown
Which team scored: home

Display cumulative score for both teams after each play

Display winner and final score

import java.util.Scanner;

public class football
{
public static void main(String [] args)
{
Scanner kbd = new Scanner(System.in);
int score = 0;
String play = "start";
while(! play.equals("end"))
{
System.out.print("Please enter a play: ");
play = kbd.next();
if (play.equals("touchdown"))
{
score = score + 6;
}
if (play.equals("touchback"))
{
score = score + 2;
}
if (play.equals("extrapoint"))
{
score = score + 1;
}
if (play.equals("fieldgoal"))
{
score = score + 3;
}
}
System.out.println("Final score is " + score);
}
}

Edited by willywhomperz: typo

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by NormR1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.