JAVA I need a switch so that users can input one selection then another. These selections are for a simple calculator that uses random numbers 1. + 2. - 3. * 4./ 5. RNG. This has to be simple this is a beginners class. Here is what I have
import java.util.Scanner;
import java.util.Random;
import java.util.*;
public class You_Michael02Basic_Calculator {
public static void main(String[] args) {
// Generate random numbers
int num1,num2;
num1
=(int)(Math.random()*100+1);
num2 =(int)
(Math.random()*100+1);
// Ask for user input
Scanner in = new
Scanner(System.in);
System.out.println("Welcome to the
RNG Calculator");
System.out.println("Please enter
your selection ::");
System.out.println("1.)
Addition");
System.out.println("2.)
Subtraction");
System.out.println("3.)
Multiply");
System.out.println("4.)
Division");
System.out.println("5.) Generate
random numbers");
int result ;
int selection = in.nextInt();
if (selection == 5)
System.out.println("Your numbers are"+num1+num2);
System.out.println("Your operator
choice ?");
int selection = in.nextInt();
switch (selection)
{
case'1': result = num1+num2;
break;
case '2' :result = num1 -
num2;
break;
case'3' :result = num1 /num2
;
break;
case '4': result = num1*num2;
break;
case '5':
default :
JOptionpane.showMessageDialog(null,"Something went wrong");
}
}
}
I'm doing this program in my laptop ....I'm submitted code screenshot and written code in my notes.



![im port oua. ut0 Scannen jaa uti Random impont Pubaic clals you michaelo1 Baiic Calculato1 Csring C] Pubaic stasic void main](http://img.homeworklib.com/questions/142e4df0-7ba3-11eb-89d4-3768d1479b91.png?x-oss-process=image/resize,w_560)


JAVA I need a switch so that users can input one selection then another. These selections...
Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...
I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...
java question, my questions are in the following codes with comments, just answer next or under it thanks! theres only few, so no worry. import java.security.SecureRandom; public class clsTestRand { public static void main(String[] args) { // TODO Auto-generated method stub //int num1, num2, num3, num4, num5, num6; int num1 = 0; int num2 = 0; int num3 = 0; int num4 = 0; int...
Java debugging in eclipse
package edu.ilstu;
import java.util.Scanner;
/**
* The following class has four independent debugging
* problems. Solve one at a time, uncommenting the next
* one only after the previous problem is working correctly.
*/
public class FindTheErrors {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
/*
* Problem 1 Debugging
*
* This problem is to read in your first name,
* last name, and current year and display them in
*...
Java Assignment Calculator with methods. My code appears below what I need to correct. What I need to correct is if the user attempts to divide a number by 0, the divide() method is supposed to return Double.NaN, but your divide() method doesn't do this. Instead it does this: public static double divide(double operand1, double operand2) { return operand1 / operand2; } The random method is supposed to return a double within a lower limit and...
Could you help me pleas , this is my code I want change it to insert student by user , and i have problem when i want append name it just one time i can't append or present more one. >>>>>>>>>>>>>>>>>>>. import java.util.Iterator; import java.util.Scanner; public class studentDLLTest { static int getChoice() { Scanner in = new Scanner(System.in); int choice; do { System.out.print("\nYour choice? : "); choice = in.nextInt(); } while (choice < 1 || choice > 9); return choice;...
IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...
I need the following java code commented import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner (System.in); int productNo=0; double product1; double product2; double product3; double product4; double product5; int quantity; double totalsales=0; while(productNo !=0) System.out.println("Enter Product Number 1-5"); productNo=input.nextInt(); System.out.println("Enter Quantity Sold"); quantity=input.nextInt(); switch (productNo) { case 1: product1=1.00; totalsales+=(1.00*quantity); break; case 2: product2=2.00; totalsales+=(2.00*quantity); break; case 3: product3=6.00; totalsales+=(6.00*quantity); break; case 4: product4=23.00; totalsales+=(23.00*quantity); break; case 5: product5=17.00; totalsales+=(17.00*quantity); break;...
need help editing or rewriting java code, I have this program
running that creates random numbers and finds min, max, median ect.
from a group of numbers,array. I need to use a data class and a
constructor to run the code instead of how I have it written right
now. this is an example of what i'm being asked
for.
This is my code:
import java.util.Random;
import java.util.Scanner;
public class RandomArray {
// method to find the minimum number in...
When I invoke the forward or backward method the current_number isnt being changed. Not sure if its something in my switch case or my methods.. package project4; import java.awt.image.BufferedImage; import java.net.URL; import java.util.Scanner; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class PictureViewer { final static int MIN_NUMBER = 0; final static int MAX_NUMBER = 8; static int image_number = 1; public static int forward(int current_number) { if (current_number < MAX_NUMBER) { return current_number ++; }...