i) Find and display the total capacity of all labs
ii) Find and display the lab with the most number of computers
iii) list the lab number, capacity and computers available in each lab
here are my coding
ADT coding:
//The objectives of this coding is to set & get data of lab number, lab capacity and
//lab computer
public class laboratory
{
private int labnum;//lab number
private int labcap;//lab capacity
private int labcomp;//numbers of computers available
public laboratory()//not appropriate for the question
{
labnum = 0;
labcap = 0;
labcomp = 0;
}
public void setlabnum(int N)
{
labnum = N;
}
public void setlabcap(int C)
{
labcap = C;
}
public void setlabcomp(int K)
{
labcomp = K;
}
public int getlabnum()
{
return labnum;
}
public int getlabcap()
{
return labcap;
}
public int getlabcomp()
{
return labcomp;
}
public String toString()
{
return("***Laboratory Data*** \n" + "Laboratory Number : " + labnum + "\nLabatory Capacity : " + labcap + "\nComputer Available : " + labcomp );
}
}
Test coding.
//
//to test class laboratory
import javax.swing.*;
public class Testlaboratory
{
public static void main (String[]args)
{
laboratory[] lab = new laboratory[10];
String str;
int labnum, labcap, labcomp;
int sum = 0;
for (int i = 0; i < 10; i++)//a) input 10 data of lab into an array
{
lab[i] = new laboratory();
str = JOptionPane.showInputDialog("Enter laboratory number : ");
labnum = Integer.parseInt (str);
str = JOptionPane.showInputDialog("Enter laboratory capacity : ");
labcap = Integer.parseInt (str);
str = JOptionPane.showInputDialog("Enter the number of computers available : ");
labcomp = Integer.parseInt (str);
lab[i].setlabnum (labnum);
lab[i].setlabcap (labcap);
lab[i].setlabcomp (labcomp);
}
for (int i = 0; i < 10; i++)//b) find & display the total capacity for all labs
{
sum += lab[i].getlabcap();
}
for (int i = 0; i < 10; i++)//c)
{
double max = lab[i].getlabcomp();
int b=0;
if (lab[i].getlabcomp() > max)
{
max = lab[i].getlabcomp();
b=i;
}
System.out.println(lab[b].toString());
}
System.out.println("The total capacity is : " +sum);
System.out.println("The lab with the most computer is : ");
}
}
can u guys help me correct my work
thanks :)


Sign In
Create Account

Back to top









