Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AakashCode12/3851cbb3998f3387d59689a929098434 to your computer and use it in GitHub Desktop.
Save AakashCode12/3851cbb3998f3387d59689a929098434 to your computer and use it in GitHub Desktop.
import areacalc.area;
import areacalc.perimeter;
//import areacalc.*;
class ar {
public static void main(String[] args) {
area a = new area();
perimeter p = new perimeter();
System.out.println("area is " + a.areaRect(4, 5));
System.out.println("area is " + a.areaSquare(5));
System.out.println("perimeter is " + p.perirect(4, 5));
System.out.println("perimeter is " + p.perisquare(5));
}
}
package areacalc;
public class area {
public static void main(String[] args) {
}
public int areaRect(int length, int breadth) {
return length * breadth;
}
public int areaSquare(int side) {
return side * side;
}
public float areaTriangle(int base, int height) {
return 0.5f * base * height;
}
}
package areacalc;
//this statement indicates the name of the package into which we want to include our class
public class perimeter {
public static void main(String[] args) {
}
public int perisquare(int side) {
return 4 * side;
}
public int perirect(int length, int breadth) {
return 2 * (length + breadth);
}
public float pericircle(float radius) {
return 2 * 3.14f * radius;
}
}

Practical 2d -- User Defined Package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment