Question

In: Computer Science

Java Programming In this assignment we are going to create our own programming language, and process...

Java Programming

In this assignment we are going to create our own programming language, and process it Java.

programming language has 6 commands

  1. enter
  2. add
  3. subtract
  4. multiply
  5. divide
  6. return

enter, add, subtract, multiply, divide all take 1 parameter (a double value).

return takes no parameters.

Solutions

Expert Solution

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;
}

}
    }
}


Related Solutions

PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
We are going to create our own implementation of the game “FloodIt”. Several versions of this...
We are going to create our own implementation of the game “FloodIt”. Several versions of this game can be found, for example a version for android, on which this description is based, here. Several Web versions are available In this game, a square board is filled with dots, each having one of six possible colours. The players initially “captures” the top left dot. The player keeps choosing one of the six colours. Each time a colour is chosen, the dots...
C++ Project 1 For this project, we are going to create our own classes and use...
C++ Project 1 For this project, we are going to create our own classes and use them to build objects. For each class you will create an *.h and *.cpp file that contains the class definition and the member functions. There will also be one file called 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them. You will create 2 new classes for this project, one will be from the list below and one...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered this week. come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. Your program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to...
C Programming Language: For this lab, you are going to create two programs. The first program...
C Programming Language: For this lab, you are going to create two programs. The first program (named AsciiToBinary) will read data from an ASCII file and save the data to a new file in a binary format. The second program (named BinaryToAscii) will read data from a binary file and save the data to a new file in ASCII format. Specifications: Both programs will obtain the filenames to be read and written from command line parameters. For example: - bash$...
Language: Java Create a TryIt.java program with a main method. You are going to use this...
Language: Java Create a TryIt.java program with a main method. You are going to use this program to demonstrate some things about how Java works. Make your methods here private, because they are not intended to be called from outside the program. For each test below, make sure that you print to the console: 1) What is being tested 2) The desired output 3) The actual output Question to be answered: Should you use == or the String method equals...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
Using the Java programming language: Create and implement a class Car that models a car. A...
Using the Java programming language: Create and implement a class Car that models a car. A Car is invented to have a gasoline tank that can hold a constant max of 12.5 gallons, and an odometer that is set to 0 for a new car. All cars have an original fuel economy of 23.4 miles per gallon, but the value is not constant. Provide methods for constructing an instance of a Car (one should be zero parameter, and the other...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT