Page 149 - Introduction to Programming with Java: A Problem Solving Approach
P. 149
4.4 && Logical Operator 115 “Fans: Redeem your ticket stub for a free order of French fries at Yummy Burgers.”
Figure 4.7 shows the framework. Within the figure, note where it says <insert code here>. Before look- ing ahead at the answer, see if you can provide the inserted code on your own.
/******************************************************************
*
FreeFries.java
Dean & Dean
This program reads points scored by the home team and the
opposing team and determines whether the fans win free
french fries.
*
*
*
*
*
*******************************************************************/
import java.util.Scanner;
public class FreeFries
{
}
// end class FreeFries
public static void main(String[] args)
{
}
int opponentPts; // points scored by opponents
Apago PDF Enhancer
System.out.print("Home team points scored: ");
homePts = stdIn.nextInt();
System.out.print("Opposing team points scored: ");
opponentPts = stdIn.nextInt();
<insert-code-here> // end main
Scanner stdIn = new Scanner(System.in);
int homePts;
// points scored by home team
Sample session:
Home team points scored: 103
Opposing team points scored: 87
Fans: Redeem your ticket stub for a free order of French fries at Yummy
Burgers.
Figure 4.7 FreeFries program with “and” condition Here’s what you should insert:
if (homePts > opponentPts && homePts >= 100)
homePts must be repeated
{
}
System.out.println("Fans: Redeem your ticket stub for" +
" a free order of French fries at Yummy Burgers.");