Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Warning sign(My program is not working right I tried to get used to dialog boxes but my program doesn't do what I want it to do )
icon4.gif  Warning sign [message #1573676] Mon, 19 January 2015 22:02 Go to next message
Michele Kinsella is currently offline Michele KinsellaFriend
Messages: 2
Registered: January 2015
Junior Member
//Basic Calculator
// January 13, 2015
// This program performs simple calculations
// //////////////////////////////////////////////////////////program without dialog boxes


import java.util.Scanner;

public class Basic_Calculator {

public static void main(String[] args) {

// create a Scanner Object
Scanner input = new Scanner(System.in);

int num1 = 0; // initialize number 1
int num2 = 0; // initialize number 2
int choice = 0; // initialize the number for the menu choice
double computanswer = 0; // initialize answer variable
double randomnumber; // initialize random number variable


Scanner input1 = new Scanner (System.in); // set up input Environment
// Set up your User menu
System.out.println("Menu choices: \n"+
"1. Add \n"+
"2. Subtract\n"+
"3. Multiply\n"+
"4. Divide\n"+
"5. Generate Random Number\n\n"+
"Please make a choice");


// collect user input
int userchoice = input1.nextInt(); // You have to create a second variable for the choice selection number on the input line

if (num1 > 5 || num1 < 1); // validate input

{
System.out.println("You have made an invalid selection"); // input validation message
}

System.out.println("Please choose a number between 1 and 5"); // This returns to the last line of the Menu





switch (userchoice) {

case 1:
System.out.println("Enter your first Number");
int choice1usernum1 = input1.nextInt(); // holds the first number the user puts in

System.out.println("Enter your second Number");
int usernum2 = input1.nextInt(); // holds the second number the user puts in

computanswer = num1 + num2; // answer to choice 1

System.out.println("Your Answer is "+computanswer);break; // converts the string to numbers


case 2:
System.out.println("Enter your first Number");
int choice2usernum1 = input1.nextInt(); // holds the first number the user puts in

System.out.println("Enter your second Number");
int choice2usernum2 = input1.nextInt(); // holds the second number the user puts in

computanswer = num1 - num2; // answer to choice 2

System.out.println("Your Answer is "+computanswer);break; // converts the string to numbers


case 3:
System.out.println("Enter your first Number");
int choice3usernum1 = input1.nextInt(); // holds the first number the user puts in

System.out.println("Enter your second Number");
int choice3usernum2 = input1.nextInt(); // holds the second number the user puts in
computanswer = num1 * num2; // answer to choice 3

System.out.println("Your Answer is "+computanswer);break; // converts the string to numbers


case 4:
System.out.println("Enter your first Number");
int choice4usernum1 = input1.nextInt(); // holds the first number the user puts in

System.out.println("Enter your second Number");
int choice4usernum2 = input1.nextInt(); // holds the second number the user puts in

computanswer = num1 / num2; // answer to choice 4

System.out.println("Your Answer is "+computanswer);break; // converts the string to numbers


case 5:

// Generate 2 Random single-digit integers Numbers
int usernumb1 = (int)(Math.random() * 100);
int usernumb2 = (int)(Math.random() * 100);

// If number 1 < number 2 , swap number 1 with number 2
if (usernumb1 < usernumb2) {

int temp = usernumb1;
usernumb1 = usernumb2;
usernumb2 = temp;
}

System.out.println("Your Answer is "+computanswer);break;


}//switch


}//public static void




private static int randomnumber() {

return 0;
}//private static int




} //public class
Re: Warning sign [message #1574874 is a reply to message #1573676] Tue, 20 January 2015 13:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Michele,

There's no question in your post and the content does not appear to be
EMF related.

On 20/01/2015 2:22 PM, Michele Kinsella wrote:
> //Basic Calculator
> // January 13, 2015
> // This program performs simple calculations
> // //////////////////////////////////////////////////////////program
> without dialog boxes
>
> import java.util.Scanner;
>
> public class Basic_Calculator {
>
> public static void main(String[] args) {
>
> // create a Scanner Object
> Scanner input = new Scanner(System.in);
>
> int num1 = 0; // initialize
> number 1
> int num2 = 0; // initialize
> number 2
> int choice = 0; //
> initialize the number for the menu choice
> double computanswer = 0; //
> initialize answer variable
> double randomnumber; // initialize
> random number variable
>
>
> Scanner input1 = new Scanner (System.in); // set up input
> Environment
> // Set up your User menu
> System.out.println("Menu choices: \n"+
> "1. Add \n"+
> "2. Subtract\n"+
> "3. Multiply\n"+
> "4. Divide\n"+
> "5. Generate Random Number\n\n"+
> "Please make a choice");
>
>
> // collect user input
> int userchoice = input1.nextInt(); // You have to
> create a second variable for the choice selection number on the input
> line
>
> if (num1 > 5 || num1 < 1); // validate input
>
> {
> System.out.println("You have made an invalid selection");
> // input validation message
> }
> System.out.println("Please choose a number between 1 and
> 5"); // This returns to the last line of the Menu
>
>
>
>
> switch (userchoice) {
>
> case 1:
> System.out.println("Enter your first Number");
> int choice1usernum1 = input1.nextInt(); //
> holds the first number the user puts in System.out.println("Enter your
> second Number");
> int usernum2 = input1.nextInt(); // holds the
> second number the user puts in
> computanswer = num1 + num2;
> // answer to choice 1
>
> System.out.println("Your Answer is
> "+computanswer);break; // converts the string to numbers
>
> case 2:
> System.out.println("Enter your first Number");
> int choice2usernum1 = input1.nextInt(); //
> holds the first number the user puts in System.out.println("Enter your
> second Number");
> int choice2usernum2 = input1.nextInt(); //
> holds the second number the user puts in
> computanswer = num1 -
> num2; // answer to choice 2
> System.out.println("Your Answer is
> "+computanswer);break; // converts the string to numbers
>
> case 3: System.out.println("Enter
> your first Number");
> int choice3usernum1 = input1.nextInt(); //
> holds the first number the user puts in System.out.println("Enter your
> second Number");
> int choice3usernum2 = input1.nextInt(); //
> holds the second number the user puts in
> computanswer = num1 * num2; //
> answer to choice 3
> System.out.println("Your Answer is
> "+computanswer);break; // converts the string to numbers
>
>
> case 4: System.out.println("Enter your first
> Number");
> int choice4usernum1 = input1.nextInt(); //
> holds the first number the user puts in System.out.println("Enter your
> second Number");
> int choice4usernum2 = input1.nextInt(); //
> holds the second number the user puts in
> computanswer = num1 /
> num2; // answer to choice 4
> System.out.println("Your Answer is
> "+computanswer);break; // converts the string to numbers
>
> case 5:
> // Generate 2 Random single-digit integers Numbers
> int usernumb1 = (int)(Math.random() * 100);
> int usernumb2 = (int)(Math.random() * 100);
> // If number 1 < number 2 , swap number 1
> with number 2
> if (usernumb1 < usernumb2) {
> int temp = usernumb1;
> usernumb1 = usernumb2;
> usernumb2 = temp;
> }
> System.out.println("Your Answer is
> "+computanswer);break;
> }//switch
>
>
> }//public static void
>
>
>
>
> private static int randomnumber() {
>
> return 0;
> }//private static int
>
>
>
>
> } //public class


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Warning sign [message #1574915 is a reply to message #1574874] Tue, 20 January 2015 14:14 Go to previous message
Erick Hagstrom is currently offline Erick HagstromFriend
Messages: 107
Registered: April 2014
Location: USA
Senior Member
Perhaps http://stackoverflow.com/ would be a better place to get help with this.
Previous Topic:Generated extensions to Switch<T> are failing null analysis
Next Topic:[Xcore] calling super method from overridden method
Goto Forum:
  


Current Time: Sat Apr 27 02:52:28 GMT 2024

Powered by FUDForum. Page generated in 0.02730 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top