AIM:
To write a Java program to find number of available seats in a college in IT2305 - Java Programming Laboratory.
class AvailSeat
{
String a[][];
int b[][],i;
public AvailSeat(int x,int y)
{
a=new String[x][];
b=new int[6][];
for(int i=0;i<a.length;i++)
a[i]=new String[y];
for(int j=0;j<b.length;j++)
b[j]=new int[6];
}
public AvailSeat()
{
a=new String[0][0];
b=new int[0][0];
}
public void getData()
{
System.out.println("Enter the 5 Department name");
Scanner sin=new Scanner(System.in);
for(int j=0;j<a[0].length;j++)
{
a[0][j]=sin.next();
}
System.out.println("Enter the available no of seats:");
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
b[i][j]=sin.nextInt();
}
}
}
public void displayData()
{
System.out.println("****************************************");
for(int i=0;i<a[0].length;i++)
{
System.out.print(a[0][i]);
System.out.print("\t");
}
System.out.println();
System.out.println("*****************************************");
for(int i=0;i<b.length;i++)
{
for(int j=0;j<b.length;j++)
{
System.out.print(b[i][j]);
System.out.print("\t");
}
System.out.println("\t");
}
System.out.println("*****************************************");
}
public void calculateSum()
{
for(int i=0;i<5;i++)
b[5][i]=b[0][i]+b[1][i]+b[2][i]+b[4][i]+b[5][i]+b[3][i];
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
{
b[i][5]+=b[i][j];
}
}
}
public class CollegeAvail
{
public static void main(String args[])
{
AvailSeat a1=new AvailSeat(5,5);
a1.getData();
a1.calculateSum();
a1.displayData();
}
}
To write a Java program to find number of available seats in a college in IT2305 - Java Programming Laboratory.
SOURCE CODE:
import java.util.*;class AvailSeat
{
String a[][];
int b[][],i;
public AvailSeat(int x,int y)
{
a=new String[x][];
b=new int[6][];
for(int i=0;i<a.length;i++)
a[i]=new String[y];
for(int j=0;j<b.length;j++)
b[j]=new int[6];
}
public AvailSeat()
{
a=new String[0][0];
b=new int[0][0];
}
public void getData()
{
System.out.println("Enter the 5 Department name");
Scanner sin=new Scanner(System.in);
for(int j=0;j<a[0].length;j++)
{
a[0][j]=sin.next();
}
System.out.println("Enter the available no of seats:");
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
b[i][j]=sin.nextInt();
}
}
}
public void displayData()
{
System.out.println("****************************************");
for(int i=0;i<a[0].length;i++)
{
System.out.print(a[0][i]);
System.out.print("\t");
}
System.out.println();
System.out.println("*****************************************");
for(int i=0;i<b.length;i++)
{
for(int j=0;j<b.length;j++)
{
System.out.print(b[i][j]);
System.out.print("\t");
}
System.out.println("\t");
}
System.out.println("*****************************************");
}
public void calculateSum()
{
for(int i=0;i<5;i++)
b[5][i]=b[0][i]+b[1][i]+b[2][i]+b[4][i]+b[5][i]+b[3][i];
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
{
b[i][5]+=b[i][j];
}
}
}
public class CollegeAvail
{
public static void main(String args[])
{
AvailSeat a1=new AvailSeat(5,5);
a1.getData();
a1.calculateSum();
a1.displayData();
}
}
EmoticonEmoticon