Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b854b3b

Browse files
authored
Merge pull request #4 from Mmabiaa/updates
Updates
2 parents 43d6a34 + d1ff09d commit b854b3b

File tree

9 files changed

+187
-0
lines changed

9 files changed

+187
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.mycompany</groupId>
5+
<artifactId>Calculator_Program</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.release>23</maven.compiler.release>
11+
<exec.mainClass>com.mycompany.calculator_program.Calculator_Program</exec.mainClass>
12+
</properties>
13+
</project>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
*/
4+
5+
package com.mycompany.calculator_program;
6+
7+
import java.util.Scanner;// A library that permits user input in java.
8+
9+
public class calculator_Program {// A simple calculator program.
10+
11+
12+
13+
//The Addition method
14+
public int Add(int a , int b){
15+
System.out.println("\n \tAddition..."); return a + b;
16+
}
17+
//The subtraction method.
18+
public int Sub(){
19+
System.out.println("\n \tSubtraction...");
20+
System.out.println("Enter your first number: ");
21+
int a = scanner.nextInt();
22+
System.out.println("Enter your second number: ");
23+
int b = scanner.nextInt();
24+
System.out.println("Answer = " + (a - b));
25+
return a - b;
26+
}
27+
28+
// The multiplication method.
29+
public int Mul(){
30+
System.out.println("\n \tMultiplication...");
31+
System.out.println("Enter your first number: ");
32+
int a = scanner.nextInt();
33+
System.out.println("Enter your second number: ");
34+
int b = scanner.nextInt();
35+
System.out.println("Answer = " + (a * b));
36+
return a * b;
37+
}
38+
39+
//The division method.
40+
public void Div(){
41+
System.out.println("\n \tDivision...");
42+
System.out.println("Enter your first number: ");
43+
int a = scanner.nextInt();
44+
System.out.println("Enter your second number: ");
45+
int b = scanner.nextInt();
46+
if (b==0){
47+
String zero ="Division by zero is invalid";
48+
System.err.println(zero);
49+
}
50+
else{
51+
System.out.println("Answer = " + (a / b));
52+
}
53+
}
54+
55+
//A method for exit.
56+
public void exit(){
57+
System.out.println("Exiting...");
58+
}
59+
60+
int option;
61+
//Main Method.
62+
public void main(String [] args){
63+
option = scanner.nextInt();
64+
int c;
65+
do{
66+
Menu(option);//calling the menu method using the args option.
67+
68+
switch (option) {
69+
case 1:
70+
Add();
71+
break;
72+
case 2:
73+
Sub();
74+
break;
75+
case 3:
76+
Mul();
77+
break;
78+
case 4:
79+
Div();
80+
break;
81+
case 5:
82+
exit();
83+
break;
84+
default:
85+
System.out.println("Unknown option");
86+
break;
87+
}
88+
System.out.println("Do you want to continue? \n (1. Yes 2. No)");
89+
c = scanner.nextInt();
90+
if (c== 2){exit();}
91+
else{
92+
System.out.println("\n\n\n");
93+
}
94+
}while(c == 1);
95+
}
96+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.mycompany.calculator_program;
2+
3+
public class Main {
4+
User_Utils user = new User_Utils();
5+
public void main(String[] args){
6+
user.display_Menu();
7+
user.accept_menu_option();
8+
9+
}
10+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.mycompany.calculator_program;
2+
import java.util.Scanner;
3+
4+
public class User_Utils {
5+
Scanner scanner = new Scanner(System.in);
6+
Calculations calculate = new Calculations();
7+
8+
9+
public double[] Accept_Values(){
10+
System.err.println("Enter First Number: ");
11+
double x = scanner.nextInt();
12+
scanner.nextLine();
13+
14+
System.err.println("Enter Second Number: ");
15+
double y = scanner.nextInt();
16+
17+
return new double[] {x, y};
18+
}
19+
20+
public void display_Menu(){
21+
System.out.println("---Welcome to the Calculator System---");
22+
System.out.println("--Menu--");
23+
System.out.println("1. Addition \n2. Subtraction \n3. Multiplication \n4. Division \n5. Exit");
24+
}
25+
26+
public void accept_menu_option(){
27+
System.out.println("Enter a menu option(1-5): ");
28+
int menu_option = scanner.nextInt();
29+
scanner.nextLine();
30+
validate_menu_option(menu_option);
31+
}
32+
33+
public void validate_menu_option(int menu_option){
34+
if (menu_option <= 5 && menu_option >=1){
35+
36+
double values[] = Accept_Values();
37+
double x = values[0];
38+
double y = values[1];
39+
40+
switch (menu_option) {
41+
case 1:
42+
double add = calculate.Addition(x, y);
43+
System.out.println("Answer = " + add);
44+
break;
45+
case 2:
46+
double sub = calculate.Subtraction(x, y);
47+
System.out.println("Answer = " + sub);
48+
break;
49+
case 3:
50+
double mul = calculate.Multiplication(x, y);
51+
System.out.println("Answer = " + mul);
52+
break;
53+
case 4:
54+
double div = calculate.Division(x, y);
55+
System.out.println("Answer = " + div);
56+
break;
57+
default:
58+
System.out.println("Thanks for using the program.");
59+
break;
60+
}
61+
}else{
62+
System.out.println("Invalid input...try again");
63+
}
64+
}
65+
}
Binary file not shown.

‎Java_Beginner_Projects/Calculator_Program/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst‎

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C:\Users\dell\OneDrive\Documents\NetBeansProjects\Calculator_Program\src\main\java\com\mycompany\calculator_program\Calculations.java
2+
C:\Users\dell\OneDrive\Documents\NetBeansProjects\Calculator_Program\src\main\java\com\mycompany\calculator_program\Main.java
3+
C:\Users\dell\OneDrive\Documents\NetBeansProjects\Calculator_Program\src\main\java\com\mycompany\calculator_program\User_Utils.java

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /