Concept explainers
Complete the following
import java.util.Scanner;
public class Checkpoint
{
public static void main(String[] args)
{
int userNum;
Scanner keyboard = new Scanner(System.in);
System.out.print(“Enter one of the numbers ” +
“1, 2, or 3: ”);
userNum = keyboard.nextInt();
//
// Write the switch statement here.
//
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Computer Science: An Overview (12th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Java How To Program (Early Objects)
- In java write a program that takes four int command-line arguments w, x, y, z,. define a boolean variable whose value is true if the four values are either in strictly acending order (w<x<y<z) or strictly descending order (w>x>y>z), and false otherwise, then display the boolean variable value. Note: Do not use if statements on the program Note: Assume that the inputs will always be integersarrow_forwardWrite a switch statement that checks nextChoice. If 0, print "Rock". If 1, print "Paper". If 2, print "Scissors". For any other value, print "Unknown". End with newline. #include <iostream>using namespace std; int main() { int nextChoice; cin >> nextChoice; /* Your solution goes here */ return 0;}arrow_forwardLanguage: JAVA PLEASE DO QUESTIONS 2 AND 3 ONLY PIN Lockout Write a code to enter a 4-digit PIN as an integer, and check if the pin is valid (the valid PIN is 1234). If the PIN is not valid print an error message “INCORRECT PIN. TRY AGAIN.” and let the user enter the PIN again. But the user only has 3 tries to enter the correct PIN. If the user enters the wrong PIN for his/her 3 tries then print “YOU HAVE RUN OUT OF TRIES. ACCOUNT LOCKED.” And if the user enters the valid PIN within the 3 tries print “PIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.” Use a while loop to prompt the user to enter a valid PIN. Do not forget to print a prompt for the user asking to enter the PIN. Create a class named PinLockout which will have the main method. All your code goes inside the main method. Sample input and output: Sample 1: ENTER YOUR PIN: 2345 INCORRECT PIN. TRY AGAIN. ENTER YOUR PIN: 2356 INCORRECT PIN. TRY AGAIN. ENTER YOUR PIN: 7564 YOU HAVE RUN OUT OF TRIES.…arrow_forward
- A. Rewrite the following program using switch statement:int main(){int testScore; // Holds a numeric test scorechar grade; // Holds a letter gradecout << "Enter your test score and I will tell you\n";cout << "the letter grade you earned: ";cin >> testScore;if (testScore = = 60)grade = 'F';if (testScore = = 70)grade = 'D';if (testScore = = 80)grade = 'C';if (testScore = = 90)grade = 'B';if (testScore = = 100)grade = 'A';cout << "Your grade is " << grade << ".\n";return 0;} B. Rewrite the following code, replacing the do-while loop with a while loop. When you do this you will no longer need an if statement. int number;cout << "Enter an even number: ";do{ cin >> number;if (number % 2 != 0)cout << "Number must be even. Reenter number: ";} while (number % 2 != 0); C. Given an array definition as follows, write the codes which will determine the highest value.const int SIZE = 10;int numbers[SIZE] = {15, 6, 3, 11, 22, 4, 0, 1, 9, 12}; D.…arrow_forwardComplete the following program so it performs the following actions 10 times:• Generates a random number that is either 0 or 1.• Displays either the word “Yes” or the word “No” depending on the random number that was generated.// Write the necessary import statement(s) here.public class ReviewQuestion16{public static void main(String[] args){// Write the necessary code here.}}arrow_forwardPython Programming. Write a program that computes how much a customer has to pay after purchasing two items. Make the lower-priced item half price. If the two items have identical prices, you can make one or the other half price. The price is calculated according to the following rules:• Buy one get one half off promotion: the lower price item is half price.• If the customer is club card member, additional 10% off.• Tax is added. Inputs to the program include:• Two items’ prices• Have club card or not (User enters ‘Y’ or ‘y’ for “yes”; ‘N’ or ‘n’ for “no”)• Tax rate (User enters the percentage as a number; for example, they enter8.25 if the tax rate is 8.25%) Program displays:• Base price - the price before the discounts and taxes• Price after discounts - the price after the buy one get one half off promotionand the member’s discount, if applicable• Total price – the amount of money the customer has to pay (after tax)printed with the precision of 2 decimal digits. Hint: In order to…arrow_forward
- Java - How do I output this statement as a horizontal statement with a newline? Everytime I use System.out.println, it makes the entire output vertical instead of horizontal. Program below. import java.util.Scanner; public class LabProgram { public static void main(String[] args) { int x; int y; Scanner scan = new Scanner(System.in); x = scan.nextInt(); y = scan.nextInt(); if(y >= x){ for(int i=x; i<=y; i = i + 5) { System.out.print(i+ " "); (The problem line) } } else{ System.out.print("Second integer can't be less than the first."); } }}arrow_forwardAllow a user to enter any number of double values up to 15. The user should enter 99999 to quit entering numbers. Display an error message if the user quits without entering any numbers; otherwise, display each entered value and its distance from the average. import java.util.*; public class DistanceFromAverage { public static void main (String[] args) { // Write your code here } }arrow_forwardWrite an equivalent if...else if...else statement to replace the following switch statement int cents; switch (cents) { case 1: System.out.println("Cent."); break; case 5: System.out.println("Nickle."); break; case 10: System.out.println("Dime."); break; case 25: System.out.println("Quarter."); break; default: System.out.println("Not a valid value."); }arrow_forward
- Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". Do NOT end with newline. import java.util.Scanner; public class YearChecker {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);int givenYear; givenYear = scnr.nextInt();arrow_forwardIN C LANGUAGE Write a menu-driven program for the following, use case/switch statement:LOL MENU1. QUADRATIC EQUATION 2. BMI CALCULATOR 3. SUM OF ODD NUMBERS 4. EXIT CHOICE:NOTE: Input another choice, if the choice is invalid. Case 1: password to open: 1111 (back to main if the password is invalid) Create a program that will calculate and display the real roots of the quadratic equation: ax2 + bx + c = 0 using the quadratic formula: x = (-b ± sqrt of b2 - 4ac) / 2a Make sure that the b2 > 4ac, so that the calculated roots will always be real. And that a must not be equivalent or less than 0. Note: Back to main after performing case 1 or exit Case 2: password to open: 1234 (back to main if the password is invalid) Create a program that will calculate Body Mass Index (BMI) and will indicate the status of your BMI. Using ladderized if-else. BMI = ([Weight in Pounds) / (Height in inches) x (Height in inches)] x 703 BMI = (Weight in Kilograms) / (Height in meters) x (Height in…arrow_forwardJava or C++ program to display the given output -----Library System----1. Add a Student2. Add a Book3. Display All Students4. Display All Books5. Search a Student6. Search a Book7. Borrow a Book8. Display Borrowed Books9. Return a Book10. Exit ➢ When 1 is chosen, ask the user to enter the student’s information(5-digit ID number,surname, first name, age, and sex)➢ When 2 is chosen, ask the user to enter the book’s information(5-digit book number,Title, Author’s name(Surname, first name), date of purchase, and status (available/notavailable))➢ When 3 is chosen, display list of all students(5-digit ID number, surname, first name,age, and sex)➢ When 4 is chosen, display list of all books(5-digit book number, Title, Author’sname(Surname, first name), date of purchase, and status (available/not available)➢ When 5 is chosen, ask the user if he wants to search the list by Surname or IDnumber. If record is found, display the corresponding record, else display anappropriate prompt.➢ When 6 is…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning