0% found this document useful (0 votes)
16 views4 pages

S 5

The document defines classes to represent places with Continent as the base class and subclasses Country, State, and Place. It creates a Place object with attributes for place, state, country, and continent. It also defines an ArrayMenu class with methods to create, display, add, multiply, and transpose 2D arrays. It takes user input to select an operation and performs it on the arrays, including creating the arrays with user input values.

Uploaded by

Deepak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

S 5

The document defines classes to represent places with Continent as the base class and subclasses Country, State, and Place. It creates a Place object with attributes for place, state, country, and continent. It also defines an ArrayMenu class with methods to create, display, add, multiply, and transpose 2D arrays. It takes user input to select an operation and performs it on the arrays, including creating the arrays with user input values.

Uploaded by

Deepak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//******************************************************************************

class Continent
{
String continent;
Continent(String c)
{
continent = c;
}
void display()
{
[Link]("Continent is: " + continent);
}
}

class Country extends Continent


{
String country;
Country(String country, String continent) {
super(continent);
[Link] = country;
}
void display()
{
[Link]();
[Link]("Country is: " + country);
}

class State extends Country


{
String state;
State(String s, String country, String continent) //c1 = country c2 =
continent
{
super(country, continent);
state = s;
}
void display()
{
[Link]();
[Link]("State is: " + state);
}
}

public class Place extends State {


String place;
Place(String p, String state, String country, String continent) //c1 =
country c2 = continent
{
super(state, country, continent);
place = p;
}
void display()
{
[Link]();
[Link]("Place is: " + place);
}

public static void main(String[] args) {


Place p = new Place("Pune", "Maharashtra", "India", "Asia");
[Link]();
}

//****************************************************************************

import [Link];
public class ArrayMenu {
int i, j, k, element;
Scanner sc = new Scanner([Link]);

void create(int arr[][], int row, int col) {


[Link]("Enter array elements: \n");
for(i=0;i<row;i++)
{
[Link]("Enter row " + (i+1) + " elements: ");
for(j=0;j<col;j++)
{
element = [Link]();
arr[i][j] = element;
}
}
}

void display(int arr[][], int row, int col) {


[Link]("Array elements are : \n");
for(i=0;i<row;i++)
{
[Link]("\n");
for(j=0;j<col;j++)
{
[Link](" " + arr[i][j]);
}
}
[Link]();
}

void addition(int arr1[][], int arr2[][], int row, int col) {


[Link]("Addition of arrays is: ");
for(i=0;i<row;i++)
{
[Link]("\n");
for(j=0;j<col;j++)
{
[Link](" " + (arr1[i][j] + arr2[i][j]));
}
}
}

void multiplication(int arr1[][], int arr2[][], int row, int col) {


[Link]("Multiplication of arrays is: ");
int res[][] = new int[row][col];
for(i=0;i<row;i++)
{
[Link]("\n");
for(j=0;j<col;j++)
{
for(k=0;k<col;k++) {
res[i][j] += arr1[i][k] * arr2[k][j];
}
[Link](" " + res[i][j]);
}

}
}

void transpose(int arr[][], int row, int col) {


[Link]("Array elements are : \n");
for(i=0;i<row;i++)
{
[Link]("\n");
for(j=0;j<col;j++)
{
[Link](" " + arr[j][i]);
}
}
[Link]();
}

public static void main(String[] args) {

int choice;
int arr1[][] = new int[10][10];
int arr2[][] = new int[10][10];
ArrayMenu a = new ArrayMenu();
Scanner sc = new Scanner([Link]);
[Link]("Enter number of rows: ");
int row = [Link]();
[Link]("Enter number of columns: ");
int col = [Link]();

while(true) {
[Link]("\n1. Create arrays. 2. Display arrays. 3.
Addition. 4. Multiplication. 5. Transpose. 6. Exit");
[Link]("Enter choice: ");
choice = [Link]();
switch(choice) {
case 1:
[Link]("***Creating array1***");
[Link](arr1,row,col);
[Link]("***Creating array2***");
[Link](arr2,row,col);
break;
case 2:
[Link]("***Display array1***");
[Link](arr1,row,col);
[Link]("***Display array2***");
[Link](arr2,row,col);
break;

case 3:
[Link](arr1,arr2,row,col);
break;

case 4:
[Link](arr1,arr2,row,col);
break;

case 5:
[Link]("***Transpose of array1***");
[Link](arr1,row,col);
[Link]("***Transpose of array2***");
[Link](arr2,row,col);
break;

case 6 :
[Link](0);

}
}

You might also like