My Name Is Salman Masood , I am Computer Science &Amp; Maths Graduate from University of Karachi, Pakistan , Teaching Is My Passion and My Aim Is to Deliver All My Knowledge among Those Students Who Can'T Afford Tutors or Expensive Institute Fees. I Will Be Keep Sharing My All Knowledge and Information with You .... Remember Me in Your Prayers !
Wednesday, 7 March 2018
inheritance in java
package calculator;
import java.util.Scanner;
class simpleCalculator
{
public float add(float a,float b)
{
return a+b;
}
public float sub(float a,float b)
{
return a-b;
}
public float mul(float a,float b)
{
return a*b;
}
public float div(float a,float b)
{
return a/b;
}
}
class simpleCalculator2 extends simpleCalculator
{
public int modulus(int a ,int b)
{
return a%b;
}
}
public class Calculator
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int a,b,choice;
float x=0;
simpleCalculator2 c=new simpleCalculator2();
System.out.println("Enter the 1st Number: ");
a=sc.nextInt();
System.out.println("Enter the 2nd Number: ");
b=sc.nextInt();
System.out.println("Press 1 for Addtion\nPress 2 for Subtraction\nPress 3 for Mulitplication\nPress 4 for Division\nPress 5 for Modulus");
System.out.println("Enter a number to Perform Airthmatic Operation: ");
choice=sc.nextInt();
switch(choice)
{
case 1:
x= c.add(a,b);
break;
case 2:
x= c.sub(a, b);
break;
case 3:
x= c.mul(a, b);
break;
case 4:
x= c.div(a, b);
break;
case 5:
x= c.modulus(a, b);
break;
}
System.out.println("Answer is "+x);
}
}
Subscribe to:
Post Comments (Atom)
Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC
Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...
No comments:
Post a Comment