Introduction to java Project

profileMarkMathlow
CS140-Project-2020-2021-T1-V33.docx

Project Report

Deadline: Thursday 25/11/2020 @ 23:59

[Total Mark for this project is 10]

Computer programming

CS140

https://www.seu.edu.sa/sites/ar/SitePages/images/logo.png

College of Computing and Informatics

pg. 2

I. Project objective:

This project is an opportunity for you to practice your knowledge in java. It will allow you to develop your skills of working within a team, thanks to your interaction with your colleagues in designing and creating a small program.

II. Project Description:

The project is about the creation of a simple calculator. The calculator should achieve different mathematical operations such as addition, multiplication, division, subtraction, modulo, cos, sin, absolute value, power, square root, minimum, maximum, …

Your program should show to the user a menu with different possible operations. The menu should contain at least seven different operations. The last option in the menu should allow the user to end the program.

Figure 1 shows an example of a menu. You have to create your menu with the operations that you have selected. It is not necessary to follow the same output given in the example.

Figure 1: Example of a menu

If the user enters a wrong number (out of the possible range), then an error message will appear and the program asks the user to reenter a correct number.

Once the user selects an operation, the program should clear the screen using the clrscr() method (Cf Figure 3, section III) then ask the user to enter the needed operand(s) and print the answer (See Figure 2)

Figure 2: Example of a menu

Once the user presses any key, the program clears the screen then the menu appears again and the user can choose a new operation.

III. Hint (how to clear the screen):

To clear the output screen when you display the menu, you can use the method: clrscr(). The program below keeps asking the user for a positive number and clears the screen each time the user gives a negative number.

import java.util.Scanner;

import java.io.IOException;

public class Main

{

//this method is used to clear the screen

public static void clrscr()

{

try

{

if (System.getProperty("os.name").contains("Windows"))

new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();

else

Runtime.getRuntime().exec("clear");

} catch (IOException | InterruptedException ex) {}

}

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.println("Give a positve number");

int a = in.nextInt();

while (a<0)

{

clrscr();//clear the screen

System.out.println("Error!! Regive a positve number");

a = in.nextInt();

}

}

}

Figure 3: How to clear the screen

IV. Marking Criteria

The program is error-free

/05

The menu is printed correctly

/10

The menu works correctly

/20

The calculator works correctly

/25

At least 7 operations are used in the calculator

/10

Output screenshots in the report

/20

The code is well documented (commented)

/10

Total

/100

Final Grade

/10

Answer

1. Brief description

Provide a brief description of your program in this section.

2. Program code

Put the code of your program in this section. Do not forget to document (comment) on your code.

3. Screenshots

Put the different screenshots with a brief description in this section (at least 6 screenshots).