954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Switch and Cases

Hi im new in Java. i have this case study and i don't know how im gonna do it.

my professor wants me to create a menu or message box that has 3 options

ex.

[ 1 ] Addition
[ 2 ] Subtraction
[ 3 ] Exit

____________

*________ this signifies a input box

if i will choose option [ 1 ] there should be another message box that will appear. inside this message box is an input box that lets u input two numbers and it will perform addition.

same as subtraction. and etc.

i need this asap.. if u cud help me now it would be better.. tnx a lot..

rLh
Newbie Poster
2 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

show some effort and come up with real questions. Don't just copy your entire assignment and wait for people to do it for you.

1) We're not here to do your homework.
2) If you don't do it yourself you'll never learn anything, and we don't want stupid kids with worthless diplomas joining the labour force.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

NEVER TREAT A NEWBIE LIKE THAT

import java.util.Scanner;
class someProggram {
 public static void main(String args[]) {
  Scanner myScanner = new Scanner (System.in);
  int sum = 0, average, largest = 0, number1, number2, smallest;
  int choice ;
  
  
 do {
  
   System.out.println("Which of the following would you like to do ");
   System.out.println("1) Find the sum");
   System.out.println("2) Find the average");
   System.out.println("3) Find the largest");
   System.out.println("4) Find the smallest");
   System.out.println("5) Quit");
   choice = myScanner.nextInt();
    
    if (choice == 1) {
     System.out.print("Enter any two numbers    ");
     number1 = myScanner.nextInt();
     number2 = myScanner.nextInt();
     sum = number1 + number2;
     System.out.println("The sum is " + sum);
     } 
     else if (choice == 2) {
      System.out.print("Enter any two numbers ");
      number1 = myScanner.nextInt();
      number2 = myScanner.nextInt();
      average = number1 + number2 / 2;
      System.out.println("The average is " + average);
     }
     else if (choice == 3) {
      System.out.print("Enter any two numbers ");
      number1 = myScanner.nextInt();
      number2 = myScanner.nextInt();
      if (number1 > number2) {
       largest = number1;
       }
       else {
       
       
        largest = number2;
       }
       System.out.println("The largest number is " +largest);
      }
      else if (choice == 4) {
       System.out.print("Enter any two numbers ");
      number1 = myScanner.nextInt();
      number2 = myScanner.nextInt();
      if(number1 < number2) {
       smallest = number1;
       }
       else {
        smallest = number2;
       }
       System.out.println("The smallest number is " +smallest);
      }
      
     
    } while (choice !=5);
    System.out.print("Thanks");
   }
 }
fastmike
Newbie Poster
9 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

and never do their homework for them.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

dont you think if he wants to go in graphics designer field y in the world he wants to learn java? all he want to do is do his homework.

fastmike
Newbie Poster
9 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

no, he doesn't want to do his homework. He wants to laze around while others do it for him.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
dont you think if he wants to go in graphics designer field y in the world he wants to learn java? all he want to do is do his homework.

It doesn't matter if he is interested in it or not. If his major requires a course of this nature, then he has to do it.

In the real world you can't just simply say "I don't like that part of my job so I simply won't do it."

That would be really great. Think about it. One of the workers in a construction company doesn't like to use screw drivers so he simply places a sticker that looks like a driven-in screwhead at every spot he was suppossed to place a screw. Then your house falls apart. But don't blame him he just simply wanted to get his work done and didn't like that part of the job.

Wonderful.

Edit:

Also, whether the major demands it or not is irrelevant. He took the course, he needs to either do the work or take the hit to his record by either failing or withdrawing. Cheating is not and never was the answer. It will catch up to you sooner or later.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You