Hey guys. I started working on a calculator about an hour ago. It's not that great at the moment, but it's something. Especially for an hour's worth of coding from a C++ noob. If anybody wants to test and give me some feedback/bugs, I'll be happy to link the DL later. It currently has only four properly working functions.
-Addition
-Subtraction
-Multiplication
-Division
I plan on adding for stuff like square rooting and multiplying using powers later on. This is a very small, useless project, I know. I'm just doing this so that I can get familiar with C++ in order to make CPPESB and modifications to the PAS engine. Thanks for your time.
Edit: Download link : http://sourceforge.net/projects/javasca ... e/download
-Java
Hi! Welcome to the forum for Platinum Arts Sandbox Free 3D Game Maker. I currently have the forums locked as I am attempting to properly update them.
In the meantime please join the new Discord Server!
If you have any questions please e-mail me through the Platinum Arts website.
In the meantime please join the new Discord Server!
If you have any questions please e-mail me through the Platinum Arts website.
Java's Calculator
-
- Member
- Posts: 194
- Joined: August 10th, 2011, 2:35 pm
- Name: Addis
- IRC Username: javaxbeast
- Location: Chicago, IL
- Contact:
Java's Calculator
Age of Darkness
Maps: Music:
Models:
Scripts:
Other:
Visit the company website: (In progress (Expected to be released in two weeks :uber:) )
Visit the company page on ModDB: Vulcanis Entertainment
java.x.beast wrote: I got them moves like JAGger!!!
-
- Member
- Posts: 3
- Joined: December 31st, 2011, 2:06 am
- Name: Langdon99
- IRC Username: Langdon99
Re: Java's Calculator
I'm learning Java bymyself and here I am trying to make a calculator but for some reason I'm getting weird values can someone revise me.
By the way I'm using my C++ knowledge as reference I don't know if it helps with java since some things are different.
Code:
import java.util.Scanner;
public class apples {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
int select = 0;
double num1=0, num2=0 , result=0;
num1 = input.nextDouble();
num2 = input.nextDouble();
result = input.nextDouble();
System.out.print("Num1 :"); System.out.print(num1); System.out.print(" Num2: "); System.out.println(num2);
System.out.print("1. Sum, 2. Subtract, 3. Multiply , 4. Divide :");
select = input.nextInt();
System.out.print(select);
if ( select ==1)
{ result = num1 + num2;
System.out.println(result);}
else if ( select ==2)
{ result = num1 - num2;
System.out.println(result); }
else if (select == 3)
{result = num1 * num2;
System.out.println(result);}
else if (select == 4)
{ result = num1 / num2;
System.out.println(result);}
else {System.out.println("Invalid");}
By the way I'm using my C++ knowledge as reference I don't know if it helps with java since some things are different.
Code:
import java.util.Scanner;
public class apples {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
int select = 0;
double num1=0, num2=0 , result=0;
num1 = input.nextDouble();
num2 = input.nextDouble();
result = input.nextDouble();
System.out.print("Num1 :"); System.out.print(num1); System.out.print(" Num2: "); System.out.println(num2);
System.out.print("1. Sum, 2. Subtract, 3. Multiply , 4. Divide :");
select = input.nextInt();
System.out.print(select);
if ( select ==1)
{ result = num1 + num2;
System.out.println(result);}
else if ( select ==2)
{ result = num1 - num2;
System.out.println(result); }
else if (select == 3)
{result = num1 * num2;
System.out.println(result);}
else if (select == 4)
{ result = num1 / num2;
System.out.println(result);}
else {System.out.println("Invalid");}
-
- Member
- Posts: 194
- Joined: August 10th, 2011, 2:35 pm
- Name: Addis
- IRC Username: javaxbeast
- Location: Chicago, IL
- Contact:
Re: Java's Calculator
Instead of using the if else if else statement so many times, you should try using the switch statement.
That should fix the problem. If anything else pops up, just let me know and I'll do my best to help.
-Java
Code: Select all
switch ( select ) {
case 1: result = num1 + num2;
System.out.println(result);
break;
case 2: result = num1 - num2;
System.out.println(result);
break;
case 3: result = num1 * num2;
System.out.println(result);
break;
case 4: result = num1 / num2;
System.out.println(result);
break;
default: System.out.println("Invalid");
break;
}
-Java
Age of Darkness
Maps: Music:
Models:
Scripts:
Other:
Visit the company website: (In progress (Expected to be released in two weeks :uber:) )
Visit the company page on ModDB: Vulcanis Entertainment
java.x.beast wrote: I got them moves like JAGger!!!
-
- Member
- Posts: 194
- Joined: August 10th, 2011, 2:35 pm
- Name: Addis
- IRC Username: javaxbeast
- Location: Chicago, IL
- Contact:
Re: Java's Calculator
I also just realized that you asked the user for three values, so the third number they entered would be the result. What you need to do to fix this is simply declare the variable and not assign it a value. The finished code would be like this.Langdon99 wrote:I'm learning Java bymyself and here I am trying to make a calculator but for some reason I'm getting weird values can someone revise me.
By the way I'm using my C++ knowledge as reference I don't know if it helps with java since some things are different.
Code:
import java.util.Scanner;
public class apples {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
int select = 0;
double num1=0, num2=0 , result=0;
num1 = input.nextDouble();
num2 = input.nextDouble();
result = input.nextDouble();
System.out.print("Num1 :"); System.out.print(num1); System.out.print(" Num2: "); System.out.println(num2);
System.out.print("1. Sum, 2. Subtract, 3. Multiply , 4. Divide :");
select = input.nextInt();
System.out.print(select);
if ( select ==1)
{ result = num1 + num2;
System.out.println(result);}
else if ( select ==2)
{ result = num1 - num2;
System.out.println(result); }
else if (select == 3)
{result = num1 * num2;
System.out.println(result);}
else if (select == 4)
{ result = num1 / num2;
System.out.println(result);}
else {System.out.println("Invalid");}
Code: Select all
import java.util.Scanner;
public class apples {
public static void main (String[] args){
Scanner input = new Scanner (System.in);
int select = 0;
double num1=0, num2=0;
num1 = input.nextDouble();
num2 = input.nextDouble();
System.out.print("Enter first number:");
System.out.print(num1);
System.out.print("Enter second number: ");
System.out.println(num2);
System.out.print("Enter 1 for Addition, 2 for Subtraction, 3 for Multiplication, and 4 for Division");
select = input.nextInt();
switch ( select ) {
case 1: result = num1 + num2;
System.out.println(result);
break;
case 2: result = num1 - num2;
System.out.println(result);
break;
case 3: result = num1 * num2;
System.out.println(result);
break;
case 4: result = num1 / num2;
System.out.println(result);
break;
default: System.out.println("Invalid");
break;
}
}
}
-Java
Age of Darkness
Maps: Music:
Models:
Scripts:
Other:
Visit the company website: (In progress (Expected to be released in two weeks :uber:) )
Visit the company page on ModDB: Vulcanis Entertainment
java.x.beast wrote: I got them moves like JAGger!!!
- Sircameron
- Member
- Posts: 62
- Joined: March 6th, 2012, 9:13 pm
- Name: Cameron
- Location: Indiana
Re: Java's Calculator
Its pretty neat! Password seems out of place, and the program stops working if 11 or more numbers are used in a single number. (Was just seeing how many numbers it could handle at once)... Still looks good though.
-
- Member
- Posts: 194
- Joined: August 10th, 2011, 2:35 pm
- Name: Addis
- IRC Username: javaxbeast
- Location: Chicago, IL
- Contact:
Re: Java's Calculator
Thanks
I've updated this project a long time ago and the password protect system is now working, complete with a function that stores the password deep inside the darkest corners of your PC for later use. I'm going to work on adding several other things including quadratic equation solver and Pythagorean Theorem solver.
-Java
I've updated this project a long time ago and the password protect system is now working, complete with a function that stores the password deep inside the darkest corners of your PC for later use. I'm going to work on adding several other things including quadratic equation solver and Pythagorean Theorem solver.
-Java
Age of Darkness
Maps: Music:
Models:
Scripts:
Other:
Visit the company website: (In progress (Expected to be released in two weeks :uber:) )
Visit the company page on ModDB: Vulcanis Entertainment
java.x.beast wrote: I got them moves like JAGger!!!
-
- Member
- Posts: 16
- Joined: November 15th, 2012, 1:32 pm
- Name: Jordan
- IRC Username: Jordy
Re: Java's Calculator
Just in case you're interested. I'm learning c++ and Ruby through Thenewboston YouTube channel. he covers a lot of different languages and the videos are well organized so it's easy to find a specific one.