Write 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. 1 import java.util.Scanner; 2 3 public class Roshambo { 4 public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int nextChoice; 6. 7 8. nextChoice scnr.nextInt(); 9. 10 /* Your solution goes here */ 11 } 13 } 12
Q: JAVA: Write a program that reads an integer and prints how many digits the number has, by checking…
A: Given: Write a program that reads an integer and prints how many digits the number has, by checking…
Q: Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End…
A: // Import the required package import java.util.Scanner; public class DetectWord { public static…
Q: Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces.…
A: import java.util.*;import java.lang.*;import java.io.*; class solution{ public static double…
Q: plain this java code
A: Descriptions: 1- Please check the following updated code with comments line by line. 2- There are…
Q: public class Test { public static void main(String[] args) { int arr[] = {1,2,3,4,5}; int count = 0;…
A: The program is to double the even elements in an array.
Q: QUESTION: Why I can't run this coding? . import java.util.*; public class Children { String…
A: import java.util.*;public class Children{ String name; int friends; public Children(String…
Q: Leave comments as explaination for how the code work. Code: import java.util.Scanner; class…
A: 1)what is functionality import java.util.Scanner ? The scanner is a class in the Java util package…
Q: Using the methods pickDir() and exractInt() as shown below, to write a simple automated game: how…
A: The program is written in java. MAXLOOPS is set to 20
Q: import java.util.Scanner; public class Juice_ordering { public static void main(String []…
A:
Q: Write an application that asks a user to type an even number or the sentinel value 999 to stop. When…
A: CODE : import java.util.*; public class EvenEntryLoop { public static void…
Q: Write a Java program StringApplication which creates a sScanner object then does the following: 1.…
A: Program Approach: Importing necessary package Defining the main class Creating Scanner object…
Q: public static int myMethod (int testValue){ final int TOP_BOUND = // ... what goes here? final int…
A: I give the code along with output and code screenshot
Q: In Java, using a single method. Seperate every warning message by a blank line. Write a program…
A: Answer: Java Source Code: public class Main{ public static void main(String[] args) {…
Q: Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant…
A: The below given java program will obey the following rubrics: Importing essential header files.…
Q: Write an expression that prints "Special number" if specialNum is -99, 0, or 44.…
A: Given: To write the expression within the if statement so that the code gives correct output. The…
Q: Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using '…
A: Code: import java.util.Scanner; public class HeightPrinter { /* Your solution goes here */public…
Q: Find the output statement that is used for debugging the following code:
A: Find the answer with reason given as below :
Q: C:\>javac TestBookingJO.java C:\>java Test BookingJO Total Booking O Total payment received:RM 900.0…
A: The program is written in Java. In this program, I added a new alert box at the end of the program.…
Q: Using a conditional expression, write a statement that increments numUsers if updateDirection is 1,…
A: As the whole program is already designed We will use the conditional statement i.e (if else) to…
Q: Write an expression that prints "Special number" if specialNum is -99, 0, or 44. 1 import…
A: File name: “FindSpecialValue.java” import java.util.Scanner; public class FindSpecialValue {…
Q: Write an expression that will cause the following code to print "Equal" if the value of…
A: Program intialized the two values traget value and sensor reading. Another value close difference is…
Q: Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces.…
A: Program code: //import the required packages import java.util.*; import java.lang.*; import…
Q: Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces…
A: A Java program for the given criteria is as follows, File name: “PopcornTimer.java” //Import the…
Q: *in java* Complete method printPopcornTime(), with int parameter bagOunces, and void return type.…
A: import java.util.Scanner; public class PopcornTimer {public static void printPopcornTime(int…
Q: A Memory Matching Game in java code with a 4x4 grid of Squares that when you click on a square it…
A: The complete code is given below.
Q: *: Implement the following class methods batterydiseount (int Byear) method takes the current year…
A: Step 1 : Start Step 2 : Define a method batterydiscount() which receives the current year and apply…
Q: Write a static method: public static double priceIsRight(Scanner s, double price) that takes a…
A: import java.util.Scanner;class Main{ static double priceIsRight(Scanner s, double price){…
Q: public class EscapeSequences { public static void main( String args[] ) { // Add a tab between…
A: Code public class EscapeSequences { public static void main(String args[]){ System.out.println("He…
Q: Create a Java project with one class StringMethods. Write the main() method with the following as…
A: Step-1: Start Step-2: Declare a string word and initialize with riGhtS Step-3: Print the original…
Q: Implement a class Balloon that models a spherical balloon that is being filled with air. The…
A: Solution :: Please find the source code , inline comments and output below . package test; import…
Q: In java Write a program on difference among if and switch?
A: import java.util.*;public class Main{ public static void main(String[] args) { char InputVar;…
Q: *** Complete in Java Program** Use Gambler's Ruin Example Gambler's ruin. Suppose a gambler makes…
A: First you need to know that what is gambler's Ruin problem : Card shark's Ruin ProblemConsider a…
Q: Implement the following class methods: isRecovered() method returns true if the old pcr result is…
A: The required problem can be addressed with the help of Java language. With the help of this…
Q: Please write the Java code for a Time class: Leave comments as explaination for how the code…
A: Solution: Given, import java.util.Scanner; class Main{publicstaticvoid main(String…
Q: Rewrite the following method using the switch statement. In your answer, you can simply use println…
A: when we need to use logical operator in case we must set the switch(true). Because after the…
Q: How can you add a new line at the the end of of the output string in Java. The output is correct but…
A: import java.util.Scanner; public class Main//LabProgram { //method drivingCost definition…
Q: Write a program that reads a mile in a double valuefrom the console, converts it to kilometers, and…
A: Since you are not mentioning the programming language, here we are using C++ to complete the…
Q: Complete the method definition to return the hours given minutes. Output for sample program:3.5…
A: As it is only needed to complete the method definition, but the whole algorithm works in the steps…
Q: 3. Write a java program as in the next class diagram, such as: SimpleCalc2 SimpleCalc2() method only…
A: ALGORITHM:- 1. Create class SimpleCalc2(). 2. Define all the member functions inside it. 3. Test the…
Q: Java - How to make this a horizontal statement with a newline. Whenever I use System.out.println, it…
A: We need to find method of how to make a horizontal statement with a newline. If System.out.println…
Q: **JAVA LANGUAGE** beginner level import java. util.Arrays; import java.util.Scanner; Suppose that…
A: import java.util.Scanner;class Main{ static double priceIsRight(Scanner s, double price){…
Q: **JAVA LANGUAGE** Beginner Level Suppose that a Scanner object contains a bunch of tokens all on…
A: Steps followed for partialSum method: Declaring and initializing the total variable and X…
Q: The Java code given below implements the method named showTwos that shows the factors of 2 in a…
A: Please find the answer below :
Q: Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A, B, C, D, E"…
A: Answer:
Q: Write a switch statement that checks origLetter. If 'a' or 'A', print "Alpha". If 'b' or 'B', print…
A: // Import the required the packageimport java.util.Scanner; public class ConvertToGreek{ public…
Q: package lab06;;public class gradereport { public static void main(String[] args) {…
A: After correcting the code, I have provided JAVA CODE along with CODE SCREENSHOT and OUTPUT…
Q: Change the program from the previous example to take command line arguments instead of using the…
A: import java.util.Scanner;public class main{public static void main(String[] args){Scanner sc = new…
Q: The question is attached to the image. Please help!
A: Create and initialize the final variable windowWidth and windowheigth. Calculate window area. int…
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
- How can you add a new line at the the end of of the output string in Java. The output is correct but it is requiring a new line I have done the System.out.println() after the 3rd method call, but it is still wrong. Here is the code with out the print line at the end and the results showing. The second picture is with the print line and showing the what is wrong as well import java.util.Scanner; public class LabProgram { //method drivingCost definition public static double drivingCost(double drivenMiles,double milesPerGallon,double dollarsPerGallon){ double yourValue; yourValue = (drivenMiles/milesPerGallon)*dollarsPerGallon; System.out.printf("%.2f ", yourValue); return yourValue;} public static void main(String[] args) { double milesPerGallon; double dollarsPerGallon; Scanner sc = new Scanner(System.in); milesPerGallon = sc.nextDouble(); dollarsPerGallon = sc.nextDouble(); drivingCost(10, milesPerGallon,…Write a java program that will create a Deck object and shuffle the deck. Then, you will draw ten cards from the deck and perform selection statements that carry out the following: If the card is red, then print “Card is red” to the screen. Otherwise, print “Card is black” to the screen. If the card is a picture card, print “That's a picture card”. If the card is an ace, print “That's an Ace”. If the card has a value less than 6, print “Card has a small value”. If the card has a value between 6 and 10 (inclusive), print “Card has a large value”. In the source code, write an algorithm for the program in a comment block. Also, in a comment block, paste the results of running your program. Print out and turn in the completed source code with those comments.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();
- Implement the Board class. Make sure to read through those comments so that you know what is required. package p1; // You need a random number generator in order to make random moves. Use rand below private static final Random rand = new Random(); private byte[][] board; /** * Construct a puzzle board by beginning with a solved board and then * making a number of random moves. Note that making random moves * could result in the board being solved. * * @param moves the number of moves to make when generating the board. */ public Board(int moves) { // TODO } /** * Construct a puzzle board using a 2D array of bytes to indicate the contents * of the cells in the triangle. * * @param b a "triangular array" with 5 rows where row 0 has 1 * cell, row 1 has 2 cells, etc. */ public Board(byte[][] b) { board = Arrays.copyOf(b, b.length); } public void printBoard() { for (int i = 0; i < board.length; i++) { for (int j = 0; j < board[i].length; j++) {…U is upward, D is downward, L is left and R is right : Using the methods pickDir() and exractInt() as shown below, to write a simple automated game: how long does it take a robot to travel from a left line of a field to the right line? Assume field is 15 units apart (meters, kilometers, it doesn’t matter), and the robot starts on the left line. pickDir(): // return string with random direction and random distance (within maxDist) public static String pickDir (int maxDist) { Random r = new Random(); // random number generator // return direction + distance return ( "" + "LRUD".charAt( r.nextInt(4) ) + (r.nextInt(maxDist) + 1) ); } extractInt(): // returns integer from string, from pos p1 to p2: str = "D1" – extractInt(str,1,1); public static int extractInt (String str, int p1, int p2) { return ( Integer.parseInt( str.substring(p1, p2+1) ) ); } Write the main() method that keeps looping until the robot’s random left…01 answer this Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces = 7: 42 seconds import java.util.Scanner; public class PopcornTimer {public static void printPopcornTime(int bagOunces) { /* Your solution goes here */ } public static void main (String [] args) {Scanner scnr = new Scanner(System.in);int userOunces; userOunces = scnr.nextInt();printPopcornTime(userOunces);}}}
- import java.util.*; public class CardGame { static Scanner scanner = new Scanner(System.in); static Random random = new Random(); public static void main(String[] args) { System.out.println("Welcome to the card game! Here are the instructions:"); System.out.println("- You will randomly draw a card from a deck of 52 cards."); System.out.println("- The computer will also draw a card from the same deck."); System.out.println("- If your card has a higher face value, you win. Otherwise, you lose."); System.out.println("- If your card has the same face value as the computer's card, the suit determines the order."); int gamesPlayed = 0; int userWins = 0; int computerWins = 0; boolean[] cards = new boolean[52]; // false means the card is available, true means it's been drawn while (true) { System.out.println("\nNew game!"); int[] userCard = drawCard(cards); int[]…Write a Java method splitName() that takes a string (that contains 1 word or more (space-separated)), split it into words, count the number of words, makes the first letter of each word capital, and display each modified word in a line. Write main() method that reads a full name (use nextLine() of the Scanner), removes eventual extra spaces, and makes all characters of the full name in lower case. Then, sends the name to splitName() method and displays the returned value. Hints: use only String methods studied so far (don’t use split() which require array manipulations that we didn’t study it yet)Write a static method userPasswordMatch(): Takes 2 String (s1, s2) input Define a boolean variable which you will return at the end of the method Check if String s1 and s2 satisfy username and password pair using “if” and “if else” Return the boolean variable as true Main Method: Set a counter to keep track how many times this program can get input from user In a loop, ask user for input: username and password Check these inputs using userPasswordMatch() method Check If userPasswordMatch() returns false then print: Username or password incorrect. And check if the value of the counter is less than 3, if that is, then print: Try again If the value of the counter is greater than 3, then print: too many attempts Otherwise, print: Login successful
- JAVA - Please produce both a product.java file and a productprinter.java file (tester) Implement a class Product. A product has a name and a price, for example new Product("Toaster", 29.95). Supply methods getName, getPrice, and reducePrice. Supply a program ProductPrinter that makes two products, prints each name and price, reduces their prices by $5.00, and then prints the prices again.Please fix this java code so that it will meet the expected output (see attached photo) import java.util.*; public class Main { public static void main(String args[]) { int numOfCash; Scanner sc = new Scanner(System.in); while(true) { System.out.print("Enter the number of cash: "); numOfCash = sc.nextInt(); sc.nextLine(); if (numOfCash <= 1) { System.out.println("Invalid"); } else { break; } } int val, total = 0; for (int i = 0; i<numOfCash; i++) { val = sc.nextInt(); sc.nextLine(); if (val < 1) { System.out.println("Invalid"); i--; continue; } total += val; } System.out.println("Total:\n" + total); }}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…