Can anybody please help me run this program. I want main() method to create 4 array objects after checking validity of quantity and price. But its not working out.Please help.
import java.io.*;
import java.util.*;
publicclass Computer2{
String[] compName = new String[4];
String[] ramSize = new String[4];
int[] hdCapacity = newint[4];
String[] pMake = new String[4];
double[] pSpeed = newdouble[4];
int[] cQuan = newint[4];
long[] cPrice = newlong[4];
int k=0;
// constructor computer2
Computer2(String name[],String size[],int capacity[],String make[], double speed[], int quan[],long price[] )
{
compName =name;
ramSize = size;
hdCapacity = capacity;
pMake = make;
pSpeed = speed;
cQuan = quan;
cPrice = price;
}
// to check validity of quantity and price
int check() {
int k=0;
if(cQuan[k]>0 && cPrice[k]>0) { return 0;}
try { if(cQuan[k]<=0);
}
catch (Exception e){
System.out.println("\nSorry! No computers available of this configuration.");
System.exit(0);}
try {if(cPrice[k]<=0);
}
catch (Exception ex){
System.out.println("\nSorry! No computers of this configuration are available at this price.");
System.exit(0); }
return 0;
} //end check
void printDescription(){
System.out.println("\nComputer Name : "+compName[k]);
System.out.println("\nRAM Size : "+ramSize[k]);
System.out.println("\nHard Disk Capacity : "+hdCapacity[k]+" GB");
System.out.println("\nProcessor Make : "+pMake[k]);
System.out.println("\nProcessor Speed : "+pSpeed[k]+" GHz");
System.out.println("\nQuantity : "+cQuan[k]);
long tPrice = cPrice[k] * cQuan[k];
System.out.println("\nTotal Price of Computers : Rs."+tPrice+"/-");
System.out.println();
}
publicstaticvoid main(String args[]) {
try {
BufferedReader bk = new BufferedReader(new InputStreamReader(System.in));
String[] name = new String[4];
String[] size = new String[4];
String[] make = new String[4];
int[] capacity = newint[4];
int[] quan = newint[4];
double[] speed = newdouble[4];
long[] price = newlong[4];
Computer2[] comp = new Computer2[4]; // Create an array of four objects
int k=0;
for(k=0;k<4;k++) {
System.out.println("\nPlease enter the name of the company : ");
name[k] = bk.readLine();
name[k].toUpperCase();
System.out.println();
System.out.println("\nPlease enter the size of the RAM : ");
size[k] = bk.readLine();
System.out.println();
System.out.println("\nPlease enter the capacity of hard disk : ");
capacity[k] = Integer.parseInt(bk.readLine());
System.out.println();
System.out.println("\nPlease enter the make of the processor : ");
make[k] = bk.readLine();
System.out.println();
System.out.println("\nPlease enter the speed of the processor :");
speed[k] = Double.parseDouble(bk.readLine());
System.out.println();
System.out.println("Please enter the number of computers : ");
quan[k] = Integer.parseInt(bk.readLine());
System.out.println();
System.out.println("Please enter the price : ");
price[k] = Integer.parseInt(bk.readLine());
System.out.println(" --- XXXX --- ");
comp[k].check();
// create objects if quantity and price are valid
if((quan[k]>0) & (price[k]>0)) {
System.out.println(" - " + comp[k]);
comp[k] = new Computer2(String name[],String size[],int capacity[],String make[], double speed[], int quan[],long price[] );
comp[k].printDescription(); }
}
System.out.println();
bk.close();
}
// catch blocks
} // End Main
} // End Computer2