Object Oriented Programming
Java Development Kit 7.2 HERE
JCreater Pro HERE
Eclipse x86 x64
Instructor's link
JAVA,How to program 8th Ed HERE
Thinking in JAVA 4th Ed HERE
HELLO WORLD
CALCULATOR
NOTE:-
"DO NOT Email as it is to sir sohaib.plzzzz....."
"It is just for helpingmy fellows."
/**
* @(#)Calculator.java
*
*
* @author Awais Ahmad Alvi BTE-SP11-012-B
* @version 1.00 2012/2/28
*/
public class Calculator {
private double op1,op2,result;
public Calculator() {
}
public void setOp1(double op_1){
op1 = op_1;
}
public void setOp2(double op_2){
op2 = op_2;
}
public double getOp1(){
return op1;
}
public double getOp2(){
return op2;
}
public double getResult(){
return result;
}
public void add(){
result = getOp1() + getOp2();
}
public void sub(){
result = getOp1() - getOp2();
}
public void multi(){
result = getOp1() * getOp2();
}
public void div(){
if(getOp2() == 0)
result = 0;
else
result = getOp1()/getOp2();
}
public void pow(){
int counter;
result = 1;
for(counter = 1;counter<=getOp2();counter++)
result = getOp1()*result;
}
}
/**
* @(#)CalculatorTest.java
*
*
* @author Awais Ahmad Alvi BTE-SP11-012-B
* @version 1.00 2012/2/28
*/
import java.util.Scanner;
public class CalculatorTest {
public static void main(String a[]){
Scanner sc = new Scanner(System.in);
Calculator cal = new Calculator();
double op1,op2,result;
int operation;
System.out.println("Enter operation\n"+"1. ADDITION\n2. SUBTRATION\n"
+"3. MULTIPLICATION"+"\n4. DIVISION\n"+"5. POWER");
operation = sc.nextInt();
System.out.println("Enter First no:");
op1 = sc.nextInt();
cal.setOp1(op1);
System.out.println("Enter Second no:");
op2 = sc.nextInt();
cal.setOp2(op2);
if(operation == 1)
cal.add();
else if(operation == 2)
cal.sub();
else if(operation == 3)
cal.multi();
else if(operation == 4)
cal.div();
else if(operation == 5)
cal.pow();
else
System.out.println("Invalid Entry");
System.out.println(cal.getResult());
}
}
Java Development Kit 7.2 HERE
JCreater Pro HERE
Eclipse x86 x64
Instructor's link
JAVA,How to program 8th Ed HERE
Thinking in JAVA 4th Ed HERE
HELLO WORLD
public class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello World!");
}
} CALCULATOR
NOTE:-
"DO NOT Email as it is to sir sohaib.plzzzz....."
"It is just for helpingmy fellows."
/**
* @(#)Calculator.java
*
*
* @author Awais Ahmad Alvi BTE-SP11-012-B
* @version 1.00 2012/2/28
*/
public class Calculator {
private double op1,op2,result;
public Calculator() {
}
public void setOp1(double op_1){
op1 = op_1;
}
public void setOp2(double op_2){
op2 = op_2;
}
public double getOp1(){
return op1;
}
public double getOp2(){
return op2;
}
public double getResult(){
return result;
}
public void add(){
result = getOp1() + getOp2();
}
public void sub(){
result = getOp1() - getOp2();
}
public void multi(){
result = getOp1() * getOp2();
}
public void div(){
if(getOp2() == 0)
result = 0;
else
result = getOp1()/getOp2();
}
public void pow(){
int counter;
result = 1;
for(counter = 1;counter<=getOp2();counter++)
result = getOp1()*result;
}
}
/**
* @(#)CalculatorTest.java
*
*
* @author Awais Ahmad Alvi BTE-SP11-012-B
* @version 1.00 2012/2/28
*/
import java.util.Scanner;
public class CalculatorTest {
public static void main(String a[]){
Scanner sc = new Scanner(System.in);
Calculator cal = new Calculator();
double op1,op2,result;
int operation;
System.out.println("Enter operation\n"+"1. ADDITION\n2. SUBTRATION\n"
+"3. MULTIPLICATION"+"\n4. DIVISION\n"+"5. POWER");
operation = sc.nextInt();
System.out.println("Enter First no:");
op1 = sc.nextInt();
cal.setOp1(op1);
System.out.println("Enter Second no:");
op2 = sc.nextInt();
cal.setOp2(op2);
if(operation == 1)
cal.add();
else if(operation == 2)
cal.sub();
else if(operation == 3)
cal.multi();
else if(operation == 4)
cal.div();
else if(operation == 5)
cal.pow();
else
System.out.println("Invalid Entry");
System.out.println(cal.getResult());
}
}
No comments:
Post a Comment