0% found this document useful (0 votes)
29 views3 pages

List Programs 1 and 3

The document describes a Java program that takes in the order of two matrices from command line arguments, reads in the values for the matrices, adds the matrices together, and displays the resultant matrix. It contains classes to read in the matrix values, add the matrices, and display the output.

Uploaded by

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

List Programs 1 and 3

The document describes a Java program that takes in the order of two matrices from command line arguments, reads in the values for the matrices, adds the matrices together, and displays the resultant matrix. It contains classes to read in the matrix values, add the matrices, and display the output.

Uploaded by

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

Develop a JAVA program to add TWO matrices of suitable order N (The value of N should be read from

command line arguments).

import java.io.*;

public class cmdTest {


int a[][]=new int[5][5];
int b[][]=new int[5][5];
int c[][]=new int[5][5];
int n;
cmdTest(){

}
void matRead(int o)throws IOException {
int i,j;
n=o;
System.out.println("Enter the First Matrix");
for(i=0;i<n;i++)
{
for(j=0;j<o;j++)
{
InputStreamReader r= new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
a[i][j] =Integer.parseInt(br.readLine());
}
}
System.out.println("Enter the Second Matrix");
for(i=0;i<n;i++)
{
for(j=0;j<o;j++)
{
InputStreamReader r= new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
b[i][j] =Integer.parseInt(br.readLine());
}
}
}
void matAdd()
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
}
void matDisp()
{
int i,j;
System.out.println("Resultant Matrix is ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(" "+c[i][j]);
}
System.out.println();
}
}
public static void main(String args[]) throws IOException {
System.out.println("Order of the Matrix: "+args[0]);
int order;
cmdTest Mat= new cmdTest();
order=Integer.parseInt(args[0]);
Mat.matRead(order);
Mat.matAdd();
Mat.matDisp();
}
}

A class called Employee, which models an employee with an ID, name and salary, is designed as shown in
the following class diagram. The method raiseSalary (percent) increases the salary by the given percentage.
Develop the Employee class and suitable main method for demonstration.

import java.io.*;
public class employee {
int EmpId;
String Name;
double Salary;
double percent;
employee(){}
employee(int Id, String Nm, double sal)
{
EmpId=Id;
Name=Nm;
Salary=sal;
}
void raiseSalary(double p) {
Salary= Salary+(Salary*p)/100;
System.out.println("Salary after the raise");
disp();
}
void disp()
{
System.out.println();
System.out.println("Employee Details :");
System.out.println("Employee ID : "+EmpId);
System.out.println("Employee Name : "+Name);
System.out.println("Employee Salary: "+Salary);
}
public static void main(String args[ ])throws IOException
{
System.out.print("Enter the Employee ID: ");
InputStreamReader r= new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
int Eid =Integer.parseInt(br.readLine());
System.out.print("Enter the Name: ");
String empName = br.readLine();
System.out.print("Enter the Salary: ");
double empSal=Double.parseDouble(br.readLine());
employee emp1 = new employee(Eid,empName,empSal);
emp1.disp();
System.out.print("Enter the Raise in Salary in Percentage: ");
double pct=Double.parseDouble(br.readLine());
emp1.raiseSalary(pct);
}
}

You might also like