0% found this document useful (0 votes)
35 views

JPR Practical Assignment 14 Solution

The document describes two Java programs. The first program creates an Area package with methods to calculate the area of a circle and rectangle. It imports the package and calls the methods. The second program creates an Arith package with a Numbers class to read numbers from the user. It extends Numbers to create an Arithmetic class that calculates addition, subtraction, multiplication, and division of the numbers.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

JPR Practical Assignment 14 Solution

The document describes two Java programs. The first program creates an Area package with methods to calculate the area of a circle and rectangle. It imports the package and calls the methods. The second program creates an Arith package with a Numbers class to read numbers from the user. It extends Numbers to create an Arithmetic class that calculates addition, subtraction, multiplication, and division of the numbers.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Create a user defined package “Area” with carea() & rarea() methods which will be
displaying area of circle & rectangle respectively. Write a Java program and access these
two methods here.

package area;

import java.io.*;

public class Info

{ public void carea() throws Exception

{ int r;

DataInputStream d=new DataInputStream(System.in);

System.out.println("\nEnter radius of circle :");

r=Integer.parseInt(d.readLine());

System.out.println("\nArea of circle :"+(3.14*r*r));

public void rarea() throws Exception

{ int l,b;

DataInputStream d=new DataInputStream(System.in);

System.out.println("\nEnter length & breadth :");

l=Integer.parseInt(d.readLine());

b=Integer.parseInt(d.readLine());

System.out.println("\nArea of rectangle :"+l*b);

import area.Info;

import java.io.*;

class result1

{ public static void main(String args[]) throws Exception

{ Info s=new Info();

DataInputStream d=new DataInputStream(System.in);

s.carea();

s.rarea();

}
}

 Output :

2. Create a user defined package “Arith” with class name as-“numbers” where read 2
numbers from user. Import above package in java program with class name as
“arithmetic” & extend above class “numbers” . Display addition, subtraction,
multiplication & division of 2 numbers.

package Arith;

import java.io.*;

public class numbers

{ protected int n1,n2;

public void in() throws Exception

DataInputStream d=new DataInputStream(System.in);

System.out.println("\nEnter two numbers :");

n1=Integer.parseInt(d.readLine());

n2=Integer.parseInt(d.readLine());

import Arith.numbers;

import java.io.*;

class arithmetic extends numbers


{ public void result() throws Exception

{ DataInputStream d=new DataInputStream(System.in);

in();

int a=n1+n2;

int b=n1-n2;

int c=n1*n2;

int di=n1/n2;

System.out.println("\nAddition : "+a);

System.out.println("Subtraction : "+b);

System.out.println("Multiplication : "+c);

System.out.println("Division : "+di);

import java.io.*;

class a3

{ public static void main(String args[]) throws Exception

{ DataInputStream d=new DataInputStream(System.in);

arithmetic a=new arithmetic();

a.result();

 Output :

You might also like