Concept explainers
Explanation of Solution
Program:
//Import necessary header files
import java.util.*;
//Declare the class
class Main
{
//Main method
public static void main(String[] args)
{
//Initialize the variable
int key = 5;
//Switch statement
switch (key + 1)
{
//Case statement
case 1:
//Print the statement
System.out.println("Cake");
//Break statement
break;
//Case statement
case 2:
//Print the statement
System.out.println("Pie");
//Break statement
break;
//Case statement
case 3:
//Print the statement
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- can you please write it in java.util.scanner form Write a program that prompts the user to enter a number within the range of 1 through 10. The program should display the Roman numeral version of that number. If the number is outside the range of 1 through 10, the program should display an error message. but use switch statement for the program.arrow_forwardCan you please Write a return method called highest CommonFactor() that returns the highest common factor of two integer numbers in the range of 1 to 100. The two numbers will be read from a file (file name is integers.inc). The file will be passed as an argument to your method and opened, read from it. You should make sure that your method can deal with the cases where one or both of the parameters are negative or zero. You may use any programming structures and methods taught in the course).arrow_forwardWhat is the value of x after the following code executes? double m = 2.67;int x = (int)m;arrow_forward
- Use JAVA to create a card game in which the dealer shuffles the deck and deals 13 cards out of the 52 to the player. The player sorts her hand and says whether it includes the King of Hearts. Repeat this process 4 times so that all the 52 cards are dealt. The player should return true or false without writing to the console. In response, the dealer should write on the console, "You won!" or "You loose again." Also create a unit test for the win and loose cases. Create an orignal code with Java card graphics. Please do not reshare a similar answer!arrow_forwardIn Kotlin, Write code that declares a nullable Int and sets its value, then declares a nullable Double and uses the safe call operator to sets its value to null if the nullable Int was null, else to the result of casting the Int to a Double. Write code that that declares a nullable Int and sets its value, then declares a nullable Double and uses the safe call operator and the Elvis operator to sets its value to 0.0 if the nullable Int was null, else to the result of casting the Int to a Double.arrow_forwardPart 2 - OddOrEven ClassIn bluej. Write a program that prompts the user to enter an integer. The program should display “The input is odd" to the screen if the input is odd and displays “The input is even" to the screen if the input is even. Hint: Consider using the mod (%) operator.arrow_forward
- Use the compareTo method to write code that reads two names from the console and prints the one that comes first in alphabetical order. For example, the program's output might look like the following: Type a name: Tyler Durden Type a name: Marla Singer Marla Singer goes before Tyler Durdenarrow_forwardCan the argument have the same name as its parameter?arrow_forwardWhat occurs when you multiply ptr by 4? Assuming that ptr is a reference to an int, what happens isarrow_forward
- Fix any errors that you find. Use in-line comments to explain how and why you fixed the bugs. Test your program. If you found and fixed all the errors, your code should function as specified: The code should allow users to enter basic, one operator arithmetic expressions using integers or doubles. Then, it should calculate the result of the expression and output the results. For example, if the user inputs “2 + 2,” the calculator should output “2 + 2 = 4.” The operations the program should perform are addition (+), subtraction (-), multiplication (*), and division (/). The user should be asked whether they wish to continue after evaluating each expression. If the user types “Y” or “y,” the program should ask for a new arithmetic expression. If the user types “N” or “n,” the program should terminate with the message: “Program Finished.”arrow_forwardAt a coffee shop , a coffee cost $1. Each coffee you purchase, earns one star. Seven stars earns a free coffee. In turn, that free coffee earns another star. Ask the user how many dollars they will spend, then output the number of coffees that will be given and output the number of stars remaining. Use A loop. Please Write the code in Java and use the test case examples as reference.arrow_forwardWhat is the value of the variable a, after the execution of the following code? int a = 4; int b = a++; Answer:arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,