prowessapps.in Package's Programs

 Create a package by name logicgate which consist of classes for AND, OR, NOT gate, and all classes has method with signature int doOperation(arg_list),
import this package in to java source file and simulate the behavior of all gates.

//File 1 : Add.java
package com.logigate;
public class Add {
 public int add(int a, int b){
  return a&b;
 }
}

//File 2 : Not.java
package com.logigate;
public class Not {
 public int not(int a){
  return ~a;
 }
}

//File 3 : Or.java
package com.logigate;
public class Or {
 public int or(int a, int b) {
  return a|b;
 }
}

// File 4: Test.java
package com.alok;
import com.logigate.*;
import java.util.Scanner;
class Test {
 public static void main(String[] a)
 {
  Add ar = new Add();
  Scanner s=new Scanner(System.in);
  System.out.print("Enter Num1: ");
  int num1 = s.nextInt();
  System.out.print("Enter Num2: ");
  int num2 = s.nextInt();
  int x = ar.add(num1,num2);
  System.out.println("Add Result= "+x);
  Or o = new Or();
  int y = o.or(num1,num2);
  System.out.println("Or Result= "+y);
  Not n = new Not();
  int z = n.not(num1);
  System.out.print("Not Result= "+z);
 }
}
OUTPUT :
Enter Num1: 5
Enter Num2: 6
Add Result= 4
Or Result= 7
Not Result= -6

 Define a package named temperature and create a class named Conversion that has a method which converts the temperature from Fahrenheit to Celsius.
Define a package named mypack and create a class that has method which calls methods of Conversion class of temperature package.

// File 1 - Conversion.java
package temperature;
public class Conversion {
 public double convert(int f) {
  double c = 5.0/9*(f-32);
  return c;
 }
}
                    
// File 2: Test.java
package mypack;
import temperature.*;
import java.util.Scanner;
class Test {
 public static void main(String[] a)
 {
  Conversion c=new Conversion();
  Scanner s=new Scanner(System.in);
  System.out.print("Enter Temp in (F): ");
  int f = s.nextInt();
  double res = c.convert(f);
  System.out.print("Temp in Cel. = "+res);
 }
}
OUTPUT :
Enter Temp in (F): 50
Temp in Cel. = 10.0

 WAP to demonstrate static import.

import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.*;
class Test {
 public static void main(String[] a)
 {
  double x = sqrt(4);
  double y = pow(2,5);
  out.println("Square root of 4- "+x);
  out.println("5 to the power of 2- "+y);
 }
} 
OUTPUT :
Square root of 4- 2.0
5 to the power of 2- 32.0 




CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved