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 | _____ |
Learn your wayIncludes step-by-step video
Chapter 3 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Introduction to Programming Using Visual Basic (10th Edition)
Artificial Intelligence: A Modern Approach
Programming in C
Starting out with Visual C# (4th Edition)
Database Concepts (8th Edition)
Problem Solving with C++ (9th Edition)
- IN JAVA. Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 77 the output is: 77 Ex: If the input is: 15 or any number not between 20 and 98 (inclusive), the output is: Input must be 20-98arrow_forwardTHIS IS IN JAVA. A restaurant serves breakfast before 11 am, after which they serve lunch. Which expression for XXX outputs the correct string for any time? Variable time ranges from 0 to 23 (e.g., 13 means 1 pm). mealString=XXX;// Output mealString A. (time > 11) ? "Breakfast" : "Lunch" B. (time == 11) ? "Breakfast" : "Lunch" C. (time < 11) ? "Breakfast" : "Lunch" D. (time != 11) ? "Breakfast" : "Lunch"arrow_forwardWrite a java program that reads in three strings and sorts them alphabetically. You can ask to enter 3 strings in three separate lines. It doesn't have to be one line. (USE IF STATMENTS OR SWITCH STATMENTS, NO LOOPS OR ARRAYS) Ex: Enter three strings: Charlie Able BakerStrings in order: Able Baker Charliearrow_forward
- In Java, the statement x++ is exactly equivalent to x = x + 1. But if x is a char, it's not exactly the same! In that case, x++ is legal, but x = x + 1 causes an error. write a java code with the error message what it is going to print. Write a java program to display a table of the integers from 0 to 10 along with their factorials. Create a Java program named StringTest.java and write a main method that contains expressions that combinevarious types using the + operator. For example, what happens when you add " a String and a char?(a)Does it perform character addition or string concatenation? (b)How can you determine the type of the result? A rational number is a number that can be represented as the ratio of two integers. For example, 2=3 is a rational number, and you can think of 7 as a rational number with an implicit 1 in the denominator.a)Define a class called Rational. A Rational object should have two integer instance variables that store the numerator and denominator.b)Write…arrow_forwardWrite a program that perform the following activities: count number of letters based on the given string “ Samuel 605; Eniola 21 Richfield java programs @ 2022 ??, semester 1!!”arrow_forwardimport java.util.Scanner; public class sample { public static double totalProfit = 0.00; public static double totalTax = 0.00; static void ProfitandTax(double S , double E , int count){ double Tax = (S * 30.00)/100.00; /* Tax is 30% of sales and it is also considered as expenses of business so this will be a type of expenses */ double totalExpense = (E + Tax ); double Profit = (S - totalExpense); // Profit is given by sales subtracted by expenses System.out.println("Profit for " + count + " branch is : " + Profit); System.out.println("Tax for " + count + " branch is : " + Tax); totalProfit += Profit; totalTax += Tax; } public static void main(String[] args){ Scanner sc = new Scanner(http://System.in); System.out.println("Enter no of branches you have "); int k = sc.nextInt(); for(int i=0;i< k ;i++){ System.out.println("Enter Sales for " + (i+1 )+ " branch " ); double S = sc.nextDouble(); System.out.println("Enter Expenses for " + (i+1) + " branch " ); double E = sc.nextDouble();…arrow_forward
- PROGRAM SIMULATION. Understand the given JAVA program and write the output. b. public class ChangeIt { public void doIt( int[] z ) { z[0] = 0; } } public class TestIt { public static void main ( String[] args ) { int[] myArray = {1, 2, 3, 4, 5} ; ChangeIt.doIt(myArray ); for (int j=0; j<myArray.length; j++ ) System.out.print( myArray[j] + " " ) ; } }arrow_forwardSuppose we add a fixed amount of money into our bank account at the beginning of every year. Modify the program from this section to show how many years it takes for the balance to double, given the annual contributions and the interest import java.util.Scanner;/**This program computes the time required to double an investmentwith an annual contribution.*/public class DoubleInvestment{public static void main(String[] args){final double RATE = 5;final double INITIAL_BALANCE = 10000;final double TARGET = 2 * INITIAL_BALANCE; Scanner in = new Scanner(System.in);System.out.print("Annual contribution: ");double contribution = in.nextDouble(); double balance = INITIAL_BALANCE;int year = 0; // TODO: Add annual contribution, but not in year 0 while(balance< TARGET) {year++;double interest = balance*(RATE/100);balance = (balance+contribution+interest);} System.out.println("Year: " + year);System.out.printf("Balance: %.2f%n", balance);}}arrow_forwardJAVA: Write a program that reads an integer and prints how many digits the number has, by checking whether the number is ≥ 10, ≥ 100, and so on. (Assume that all integers are less than ten billion.) If the number is negative, first multiply it with –1.arrow_forward
- Do a program that displays a simulated writing check.Use supplied Check.java and CheckDemo.java.It should then display a simulated check with the dollar amount spelled out,as shown. Check.Demo package checks; import java.time.LocalDate; public class Check { private double amount; private String payee; private LocalDate date; /* * Constructor */ public Check(double amount, String payee, LocalDate date) { // Your code here } public Check(Check original) { // Your code here } /* * Returns a String representing the check */ public String toString() { String result = "\t\t\t\tDate:\t"; result += date.getMonthValue() + "/"; result += date.getDayOfMonth() + "/"; result += date.getYear() + "\n\n"; result += "Pay to the Order of: " + payee + "\t\t"; result += "$" + amount + "\n\n"; result += amountText() + "\n"; return result;// return amountText(); } private…arrow_forwardWRITE A JAVA PROGRAM Methods can be used to define reusable code and organize and simplify code. Problem:- Suppose that you need to find the sum of integers from 5 to 15, from 16 to 30, and from 31 to 39, respectively. Define a public static sum method that take two int parameters -> (int start, int end) In the method, use for loop to add all the number from start to end. Later, invoke the sum inside the main method. Do the sum for each a) 5 to 15; b) 16 to 30; and c) 31 to 39 separately and later print the results. Output: Sum from 5 to 15 is 110 Sum from 16 to 30 is 345 Sum from 31 to 39 is 315arrow_forwardWhat is the number of operations executed when the following Java code runs? Your answer is expected to be in terms of n. The rules for counting operations in Pseudocode apply for Java code, StdOut.println() and Integer.parseInt(args[0]) are equivalent to DISPLAY and READ respectively. public class RandomSequence { public static void main ( String[] args ) { int n = Integer.parseInt(args[0]); for (int i = 0; i < n; i++) { StdOut.println(Math.random()); } } }arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT