In: Computer Science
Java Programming
In this assignment we are going to create our own programming language, and process it Java.
programming language has 6 commands
enter, add, subtract, multiply, divide all take 1 parameter (a double value).
return takes no parameters.
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int x = 0;
Scanner s = new
Scanner(System.in); //Scanner class for Taking input
public int
enter(double x)
{
System.out.println("Enter the number to perform operations
");
System.out.print("Enter the number : ");
x = s.nextInt();
return x;
}
while(true){
System.out.println("Choose
the operation you want to perform ");
System.out.println("Choose
1 for ADDITION");
System.out.println("Choose
2 for SUBTRACTION");
System.out.println("Choose
3 for MULTIPLICATION");
System.out.println("Choose
4 for DIVISION");
System.out.println("Choose
5 for Return");
int
n = s.nextInt();
switch(n)
{
case
1:
int x = enter(1);
void add(double x){
System.out.println(x+x);
}
break;
case
2:
int x = enter(1);
void sub(double x){
System.out.println(x-x);
}
break;
case
3:
int x = enter(1);
void
mul(double x){
System.out.println(x*x);
}
break;
case
4:
int x = enter(1);
void
div(double x){
System.out.println(x+x);
}
break;
case
5:
return;
default:
break;
}
System.out.println("do
you want to continue y/n");
char l=in.next().charAt(0)
if(l!='y')
{
break;
}
}
}
}