Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 3.4, Problem 3.15CP

The following program is used in a bookstore to determine how many discount coupons a customer gets. Complete the table that appears after the program.

import javax.swing.JOptionPane;

public class Checkpoint

{

 public static void main(String[] args)

 {

 int books, coupons;

 String input;

 input = JOptionPane.showInputDialog(“How many books ” +“are being purchased? ”);

 books = Integer.parseInt(input);

 if (books < 1)

  coupons = 0;

 else if (books < 3)

  coupons = 1;

 else if (books < 5)

  coupons = 2;

 else

  coupons = 3;

 JOptionPane.showMessageDialog(null, “The number of coupons to give is ” + coupons);

 System.exit(0);

}

}

If the customer purchases this many books … this many coupons are given.
1 _____
2 _____
3 _____
4 _____
5 _____
10 _____
Blurred answer
Students have asked these similar questions
In Java trace the table for a while loop  public class Main { public static void main(String[] args) { // Question 2 j = 30; x=5; for (int i=1;i<=2;i++) { while (j > 20) { j=j-x*i; ++x; }// end of while }// end of for j x i j<=2 j>20
Change Java code below so that it outputs a 9x9 board and not a 3x3 board. import java.util.*; public class Tic_Tac_Toe{ static String[] board;static String turn;static String checkWinner(){for (int a = 0; a < 8; a++) {String line = null; switch (a) {case 0:line = board[0] + board[1] + board[2];break;case 1:line = board[3] + board[4] + board[5];break;case 2:line = board[6] + board[7] + board[8];break;case 3:line = board[0] + board[3] + board[6];break;case 4:line = board[1] + board[4] + board[7];break;case 5:line = board[2] + board[5] + board[8];break;case 6:line = board[0] + board[4] + board[8];break;case 7:line = board[2] + board[4] + board[6];break;}//For X winnerif (line.equals("XXX")) {return "X";} // For O winnerelse if (line.equals("OOO")) {return "O";}} for (int a = 0; a < 9; a++) {if (Arrays.asList(board).contains(String.valueOf(a + 1))) {break;}else if (a == 8) {return "draw";}} // To enter the X Or O at the exact place on board.System.out.println(turn + "'s turn; enter…
IN JAVA - Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 5 as long as the value is less than or equal to the second integer. End with a newline. Ex: If the input is: -15 10 the output is: -15 -10 -5 0 5 10 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a space after every integer, including the last. BASE CODE:  import java.util.Scanner; public class LabProgram {   public static void main(String[] args) {      /* Type your code here. */   }}

Chapter 3 Solutions

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Ch. 3.2 - Write an if-else statement that assigns 0 to the...Ch. 3.3 - Write nested if statements that perform the...Ch. 3.3 - Write code that tests the variable x to determine...Ch. 3.4 - What will the following program display? public...Ch. 3.4 - The following program is used in a bookstore to...Ch. 3.5 - Prob. 3.16CPCh. 3.5 - Assume the variables a = 2, b = 4, and c = 6....Ch. 3.5 - Write an if statement that displays the message...Ch. 3.5 - Prob. 3.19CPCh. 3.6 - Assume the variable name references a String...Ch. 3.6 - Prob. 3.21CPCh. 3.6 - Prob. 3.22CPCh. 3.8 - Rewrite the following if-else statements as...Ch. 3.9 - Complete the following program skeleton by writing...Ch. 3.9 - Rewrite the following if-else-if statement as a...Ch. 3.9 - Explain why you cannot convert the following...Ch. 3.9 - What is wrong with the following switch statement?...Ch. 3.9 - What will the following code display? int funny =...Ch. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Prob. 3.30CPCh. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Prob. 3.32CPCh. 3.10 - Prob. 3.33CPCh. 3.10 - Assume the following declaration exists in a...Ch. 3 - The if statement is an example of a __________. a....Ch. 3 - This type of expression has a value of either true...Ch. 3 - , , and = = are __________. a. relational...Ch. 3 - , | |, and ! are __________. a. relational...Ch. 3 - Prob. 5MCCh. 3 - To create a block of statements, you enclose the...Ch. 3 - This is a boolean variable that signals when some...Ch. 3 - How does the character A compare to the character...Ch. 3 - This is an if statement that appears inside...Ch. 3 - Prob. 10MCCh. 3 - When determining whether a number is inside a...Ch. 3 - Prob. 12MCCh. 3 - The conditional operator takes this many operands....Ch. 3 - This section of a switch statement is branched to...Ch. 3 - You can use this method to display formatted...Ch. 3 - True or False: The = operator and the == operator...Ch. 3 - True or False: A conditionally executed statement...Ch. 3 - Prob. 18TFCh. 3 - True or False: When an if statement is nested in...Ch. 3 - True or False: When an if statement is nested in...Ch. 3 - True or False: The scope of a variable is limited...Ch. 3 - Find the errors in the following code: 1. //...Ch. 3 - Find the errors in the following code: 2. //...Ch. 3 - Find the errors in the following code: 3. //...Ch. 3 - Prob. 4FTECh. 3 - Find the errors in the following code: 5. The...Ch. 3 - Find the errors in the following code: 6. The...Ch. 3 - The following statement should determine whether...Ch. 3 - Find the errors in the following code: 8. The...Ch. 3 - Prob. 9FTECh. 3 - Prob. 10FTECh. 3 - Write an if statement that assigns 100 to x when y...Ch. 3 - Write an if-else statement that assigns 0 to x...Ch. 3 - Using the following chart, write an if-else-if...Ch. 3 - Write an if statement that sets the variable hours...Ch. 3 - Write nested if statements that perform the...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if-else statement that displays the...Ch. 3 - Convert the following if-else-if statement into a...Ch. 3 - Match the conditional expression with the if-else...Ch. 3 - Prob. 12AWCh. 3 - Prob. 13AWCh. 3 - Prob. 14AWCh. 3 - Explain what is meant by the phrase conditionally...Ch. 3 - Explain why a misplaced semicolon can cause an if...Ch. 3 - Why is it good advice to indent all the statements...Ch. 3 - What happens when you compare two String objects...Ch. 3 - Prob. 5SACh. 3 - What risk does a programmer take when not placing...Ch. 3 - Prob. 7SACh. 3 - Briefly describe how the | | operator works.Ch. 3 - Why are the relational operators called...Ch. 3 - When does a constructor execute? What is its...Ch. 3 - Roman Numerals Write a program that prompts the...Ch. 3 - Magic Dates The date June 10, 1960, is special...Ch. 3 - Body Mass Index Write a program that calculates...Ch. 3 - Test Scores and Grade Write a program that has...Ch. 3 - Mass and Weight Scientists measure an objects mass...Ch. 3 - Time Calculator Write a program that asks the user...Ch. 3 - Sorted Names Write a program that asks the user to...Ch. 3 - Software Sales A software company sells a package...Ch. 3 - Shipping Charges The Fast Freight Shipping Company...Ch. 3 - Fat Gram Calculator Write a program that asks the...Ch. 3 - Running the Race Write a program that asks for the...Ch. 3 - The Speed of Sound The following table shows the...Ch. 3 - Mobile Service Provider A mobile phone service...Ch. 3 - Mobile Service Provider, Part 2 Modify the program...Ch. 3 - Prob. 15PCCh. 3 - Book Club Points Serendipity Booksellers has a...Ch. 3 - Wi-Fi Diagnostic Tree Figure 3-23 shows a...Ch. 3 - Restaurant Selector You have a group of friends...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY