Professional Documents
Culture Documents
CORRECTED 3rd Time
CORRECTED 3rd Time
CORRECTED 3rd Time
Algorithm
Step 1 - Start
Step 2 –Take a Square matrix a[][] of order n
Step 3 - Accept variables r and c as number of rows and
columns
Step 4 – Take the elements in the array
Step 5 – Find the minimum of a row and return the index
position
Step 6 - Display the saddle point
Step 7 - Create a main function
Step 8 – Create an object and calling the parent class method
Step 9 – Stop
Program
VARIABLE DESCRIPTION
Variable Datatype Description
a[][] int To store the array
elements
r int To enter the
number of rows
c int To store the
number of
columns
a[][] int Array to store the
elements
min int To store the
minimum value
max int To store the
maximum value
p int To store loop
variable (i)
i int Loop variable
j int Loop variable
mp int To store the value
of min.
OUTPUT
Question 2
Algorithm
Step 1 - Start
Step 2 - Taking a square matrix a[][] of size n
Step 3 - Initialize value to be filled in matrix
Step 4 - accepting k , m , l and n
Step 5 - Print the first row from the remaining rows
Step 6 - Print the last column from the remaining column
Step 7 - Print the first column from the remaining columns
Step 8 - Driver program to test above function
Step 9 - Stop
Program
import java.util.*;
public class Spiral
{
void spiralFill(int m, int n, int a[][])
{
// Initialize value to be filled in matrix
int val = 1;
k++;
OUTPUT
Question 3
Algorithm
Step 1- Start
Step 2- Accepting an integer array arr[] and length of an
array len
Step 3- Accepting the memeber methods
Step 4- Accepting an integer element l as parameterized
constructor to assign
the length of an array
Step 5- A collection containing the common elements of
current collection
object and the collection object passed as a parameter
Step 6- Sorting the array elements of the object containing
common elements is
ascending order
Step 7- Displaying the array elements
Step 8- A main function is created
Step 9- Two objects c1 and c2 has been created for calling
the member methods
from the parent class.
Step 10- Stop
Program
import java.util.*;
public class Collection
{
Scanner sc=new Scanner(System.in);
int arr[]=new int[100];
int len;
public Collection()
{
len=0;
for(int i=0;i<100;i++)
arr[i]=0;
}
public Collection(int l)
{
len=l;
for(int i=0;i<len;i++)
arr[i]=0;
}
public void inpar()
{
for(int i=0;i<len;i++)
{
System.out.println("Enter the element:");
arr[i]=sc.nextInt();
}
}
Collection common(Collection c)
{
Collection c1=new Collection(len);
int i,j,f,k=0;
for(i=0;i<len;i++)
{
f=0;
for(j=0;j<c.len;j++)
{
if(arr[i]==c.arr[j])
f=1;
}
if(f==1)
{
c1.arr[k]=arr[i];
k++;
}
}
c1.len=k;
return c1;
}
public void arrange()
{
int i,j,t;
for(i=0;i<len;i++)
{
for(j=0;j<len-i-1;j++)
{
if(arr[j]>arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
}
public void display()
{
System.out.println("The elements:");
for(int i=0;i<len;i++)
{
System.out.print(arr[i]+" ");
}
}
public static void main()
{
Collection c1=new Collection(5);
Collection c2=new Collection(4);
Collection c3=new Collection(4);
System.out.println("First array:");
c1.inpar();
System.out.println("Second array:");
c2.inpar();
c3=c1.common(c2);
System.out.println("\nCommon elelments:");
c3.display();
System.out.println("\nCommon elelments in sorted
order:");
c3.arrange();
c3.display();
}
}
Output-
Varaiable description
Variable Datatype Purpose
len int To accept Length
Arr[][] int Array element
I int Loop variable
j int Loop variable
f int To check the
variable
k int To show length of
c1
t int To assign the
array
Question 4
Algorithm
Step 1 - Start
Step 2 - Accept the distances as kilometer and meter
Step 3 - Assign kilometer into x and meter in y
Step 4 - Take input as distance a and b
Step 5 - Now calculate the distance.
Step 6 - Check conditions of dN
Step 7- Enter distance
Step 8 - Calculate d1,d2,d3
Step 9 - Print d3 and sum distance
Step 10 - Stop
Program
import java.util.*;
public class Distance
{
double M,N;
public Distance(double x,double y)
{
M=x;
N=y;
}
public void display()
{
System.out.println(M+"km"+" "+N+"m");
}
public Distance Add_Dis(Distance a,Distance b)
{
Distance d=new Distance(0,0);
d.M=a.M+b.M;
d.N=a.N+b.N;
if(d.N>=1000)
{
d.M+=1;
d.N-=1000;
}
return d;
}
public static void main()
{
Scanner sc = new Scanner(System.in);
double k,m,k1,m1;
System.out.println("Enter first distance");
k=sc.nextDouble();
m=sc.nextDouble();
System.out.println("Enter 2nd distance:");
k1=sc.nextDouble();
m1=sc.nextDouble();
Distance d1=new Distance(k,m);
Distance d2=new Distance(k1,m1);
Distance d3=new Distance(0,0);
d3=d1.Add_Dis(d1,d2);
System.out.println("The sum distance:");
d3.display();
}
}
Variable Description
Output
Question 5
Program
}
public class Account extends Bank
{
double am;
Account(String n, long ac, double ammt, double amt)
{
super(n,ac,ammt);
amt=am;
}
Output
Variable description
Question6
A superclass Product has been defined to store the details of
a product sold by a wholesaler to a retailer. Define a subclass
Sales to compute the total amount paid by the retailer with
or without fine along with service tax. Some of the members
of both classes are given below:
Algorithm
Step 1 - Start
Step 2 - accpet variables name , code and amount
Step 3 - assign n into name , c into code and amount into p
Step 4 - Print name of the product
Step 5 - Print product code
Step 6 - Print amount of the product
Step 7 - Subclass Sales has been created
Step 8 - Parameterized constructor to assign values to data
members of both the classes
Step 9 - Calculate the total amount with tax and fine
Step 10 - Stop
Program
import java.util.*;
class Product
{
String name; int code;double amount;
Product( String n,int c, double p)
{
name=n;
code=c;
amount=p;
}
void show()
{
System.out.println("Name of the product:"+name);
System.out.println("Product Code:"+code);
System.out.println("Total sale amount of the
product:"+amount);
}
}
class Sales extends Product
{
int day;double tax;double totamt;double fine;
Sales(String n,int c, double p,int d,double ta,double tot)
{
super(n,c,p);
day=d;
tax=ta;
totamt=tot;
}
void compute()
{
tax=12.4/100.0*amount;
if(day>30)
fine=2.5/100.0*amount;
totamt=amount+tax+fine;
}
void show()
{
super.show();
System.out.println("Total amount to be paid:"+totamt);
}
}
Output
(missing because error in the program)
Variable description