Question

I am learning programming in JAVA. Please help me with this programming assignment. Your lab assignment...

I am learning programming in JAVA. Please help me with this programming assignment.

Your lab assignment this week is to build a little math program to help kids practice their addition and subtraction.

You will create a menu and have the kid select what kind of math problem they want to solve.

Once the kid selects what kind of problem. Randomly generate two numbers, display the problem and allow the kid to enter the answer. If the answer is correct. display a message. If the answer is incorrect, let the kid know the answer is incorrect and display the correct answer.

Requirements:

- use switch...case statements for the menu

- if..then...else statements

- mathematic calculations

- use random class

- once completed please upload your main.java file or paste code

Sample output:

***** Menu *****

1. Addition

2. Subtraction

***************

Enter selection: 1

You selected Addition

1+2 =

Enter answer: 3

You are correct!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;
import java.util.Scanner;


public class RandomAddition {
   public static void main (String args[])
   {
  
       Scanner scan = new Scanner(System.in);

  
   Random r1 = new Random();
   int num1=r1.nextInt(10);
   int num2=r1.nextInt(10);
   int result;
   System.out.print("**********MENU*********\n");
   System.out.println("1. Addition");
   System.out.println("2. Subtraction");
   System.out.println("Enter selection: ");
   int select=scan.nextInt();
     
   //switch case statement
   switch(select)
   {
          case 1:
              result=num1+num2;
              System.out.println("You selected Addition");
              System.out.println(num1+"+"+num2+"= ");
              System.out.print("Enter answer: ");
              int res=scan.nextInt();
              if(res==result)
                  System.out.println("You are correct!!!");
              else
              {
                  System.out.println("Answer is incorrect, correct answer is: "+result);
              }
              break;
          case 2:
              int temp;
              if(num1<num2)
              {
                  temp=num1;
                  num1=num2;
                  num2=temp;
              }
              result=num1-num2;
             
              System.out.println("You selected Subtraction");
              System.out.println(num1+"-"+num2+"= ");
              System.out.print("Enter answer: ");
              res=scan.nextInt();
              if(res==result)
                  System.out.println("You are correct!!!");
              else
              {
                  System.out.println("Answer is incorrect, correct answer is: "+result);
              }
              break;
          default:
              System.out.println("invalid input");
             
   }
     
   }

}

Add a comment
Know the answer?
Add Answer to:
I am learning programming in JAVA. Please help me with this programming assignment. Your lab assignment...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a web page that will help students practice math - Addition, Subtraction, Multiplication and Division....

    Create a web page that will help students practice math - Addition, Subtraction, Multiplication and Division. The page should generate and display a math problem using 2 random numbers from 1 to 12. Addition: [1 - 12] + [1 - 12] = [2 - 24]<-Calculated Subtraction: [2 - 24]<-Calculated - [1 - 12] = [1 - 12] Multiplication: [1 - 12] * [1 - 12] = [1 - 144]<-Calculated Division: [1 - 144]<-Calculated / [1 - 12] = [1 -...

  • Android / Java / Please Upload your homework. Copy the screenshot and then paste it to...

    Android / Java / Please Upload your homework. Copy the screenshot and then paste it to this word document. Then zip your word file and java files. Note: if your android project is too big, you can just zip all of the needed xml files and java files. Computer-Assisted Instruction App) Create an app that will help an elementary school student learn multiplication. Select two positive one-digit integers. The app should then prompt the user with a question, such as...

  • This week we looked at an example math program that would display the answer to a...

    This week we looked at an example math program that would display the answer to a random math problem. Enhance this assignment to prompt the user to enter the solution to the displayed problem. After the user has entered their answer, the program should display a message indicating if the answer is correct or incorrect. If the answer is incorrect, it should display the correct answer. The division section should use Real data types instead of Integer data types. Keep...

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • Please help me with the following question. This is for Java programming. In this assignment you...

    Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

  • Java programming: please help with the following assignment: Thank you. Create a class called GiftExchange that...

    Java programming: please help with the following assignment: Thank you. Create a class called GiftExchange that simulates drawing a gift at random out of a box. The class is a generic class with a parameter of type T that represents a gift and where T can be a type of any class. The class must include the following An ArrayList instance variable that holds all the gifts,The ArrayList is referred to as theBox. A default constructors that creates the box....

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

  • Can someone please help me with how to write this in Java? You will write a...

    Can someone please help me with how to write this in Java? You will write a program to evaluate a math expression given by a user. • Read the input from the scanner • Expressions should match the forms below. Note that you will need spaces between the numbers and operators for your scanner methods to work best. - “number1 operator number2” - “operator number1” • Declare number1 and number2 as type integer. Test using integer values. • You must...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT