Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Calculater
Index -> Programming, Java -> Java Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
r.m_spy




PostPosted: Fri Apr 23, 2010 5:18 pm   Post subject: Calculater

Java:

class calculator
{
public static void main(String[]args)
{
double num1,num2,ans;
char op;
System.out.println("Welcome to Calculator 1.0.");
System.out.println("");
System.out.println("Please enter your first number.");
num1=In.getDouble();
System.out.println("Please enter your operation. press ? for help.");
op=In.getChar();
if (op=='|')
{
ans=Math.sqrt(num1);
System.out.println("The Square root of "+num1+" is "+ans);
System.out.print("To end this program, enter another number. ");
}
if (op=='`')
{
ans=Math.round(num1);
System.out.println("If you round "+num1+", you get "+ans+".");
System.out.print("To end this program, enter another number. ");
}
System.out.println("Please enter your second number.");
num2=In.getDouble();
switch(op)
{
case '+':
ans=num1+num2;
System.out.println(num1+" + "+num2+" = "+ans);
break;
case '-': 
ans=num1-num2;
System.out.println(num1+" - "+num2+" = "+ans);
break;
case '*':
ans=num1*num2;
System.out.println(num1+" X "+num2+" = "+ans);
break;
case '/':
ans=num1/num2;
System.out.println(num1+" / "+num2+" = "+ans);
break;
case '^':
ans=Math.pow(num1,num2);
System.out.println(num1+" ^ "+num2+" = "+ans);
break;
case '~':
System.out.println("Pie is equal to "+ Math.PI);
System.out.println("E is equal to "+ Math.E);
break;
case '?':
System.out.println("To add, use the symbol +");
System.out.println("To subtract, use the symbol -");
System.out.println("To multiply, use the symbol *");
System.out.println("To divide, use the symbol /");
System.out.println("To square, use the symbol ^");
System.out.println("To square root, use the symbol |");
System.out.println("To get the value of pie and e, use the symbol ~");
System.out.println("To round, use the symbol `");
break;
}
}
}




DrawingLines.java
 Description:
BONUS FILE drawing lines

Download
 Filename:  DrawingLines.java
 Filesize:  592 Bytes
 Downloaded:  261 Time(s)


calculator.java
 Description:
My calculator.java

Download
 Filename:  calculator.java
 Filesize:  1.75 KB
 Downloaded:  261 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
USEC_OFFICER




PostPosted: Sat Apr 24, 2010 2:49 pm   Post subject: RE:Calculater

Can you please explain what this is for? Just wondering. A preamble would have been nice.
r.m_spy




PostPosted: Sat Apr 24, 2010 9:05 pm   Post subject: RE:Calculater

A) calculator has you enter two numbers, and a symbol, and calculates

(press ? for help)

the other is a no-point applet
Display posts from previous:   
   Index -> Programming, Java -> Java Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: