List Programs 1 and 3
List Programs 1 and 3
import java.io.*;
}
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);
}
}