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
  • 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...

  • this is for java programming Please use comments Use the Account class created in homework 8_2...

    this is for java programming Please use comments Use the Account class created in homework 8_2 to simulate an ATM machine. Create ten checking accounts in an array with id 0, 1, …, 9, initial balance of $100, and annualInterestRate of 0. The system prompts the user to enter an id between 0 and 9, or 999 to exit the program. If the id is invalid (not an integer between 0 and 9), ask the user to enter a valid...

  • Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS...

    Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS PLEASE EMAIL ME! This programming assignment will just be a small extension to programming assignment 1. In the first assignment each of the functions could only take a predefined number of inputs. This time the objective is to be able to complete these functions with any amount of inputs. The user will pass arguments through the command line (this means you will have to...

  • please help! Write a program that can be used as a math tutor for a young...

    please help! Write a program that can be used as a math tutor for a young student. The program should display two random numbers to be added. The program should then pause while the student works on the problem. When the student is ready to check the answer, he or she can press a key and the program will display the correct solution. The output must be formatted correctly with the numbers aligned properly. You will build on this assignment...

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
ADVERTISEMENT