hey...how can i use the dialog box joption for now i just use the normal display when i do the joption there alot of error can anyone help thanks.

package javaapplication1;
import java.util.Scanner;


public class JavaApplication1 {
    static int MicrowaveNetPerIntem =638,JuicerNetPerIntem=270,CookerNetPerItem=216,OvenNetPerItem=229;    
    static Scanner input=new Scanner(System.in);
    static int MicrowaveSellingPrice=1338;
    static int JuicerSellingPrice=650;
    static int CookerSellingPrice=366;
    static int OvenSellingPrice=479;
    static int selection;
    static String Item;
    static int max = 0;  

    static int[] QuantitySoldArry = new int[12];


    public static void main(String[] args) {

    System.out.println("*************************************\nWelcome to Revenue Calculating Syste.\n*************************************\n\n");
        System.out.println("Please Enter the quantity of item sold in each months.\n");
        System.out.println("Microwave sold in October: ");
        QuantitySoldArry[0]=input.nextInt();        
        System.out.println("Microwave sold in November: ");
        QuantitySoldArry[1]=input.nextInt();        
        System.out.println("Microwave sold in December: ");
        QuantitySoldArry[2]=input.nextInt();        
        System.out.println("Juicer sold in October: ");
        QuantitySoldArry[3]=input.nextInt();        
        System.out.println("Juicer sold in November: ");
        QuantitySoldArry[4]=input.nextInt();        
        System.out.println("Juicer sold in December: ");
        QuantitySoldArry[5]=input.nextInt();        
        System.out.println("Multipurpose Cooker sold in October: ");
        QuantitySoldArry[6]=input.nextInt();        
        System.out.println("Multipurpose Cooker sold in November: ");
        QuantitySoldArry[7]=input.nextInt();        
        System.out.println("Cooker sold in December: ");
        QuantitySoldArry[8]=input.nextInt();          
        System.out.println("Oven sold in October: ");
        QuantitySoldArry[9]=input.nextInt();        
        System.out.println("Oven sold in November: ");
        QuantitySoldArry[10]=input.nextInt();        
        System.out.println("Oven sold in December: ");
        QuantitySoldArry[11]=input.nextInt();         

       System.out.println("**************************\nSelect a number to display\n************************\n");

        System.out.println("1: Gross Income");
        System.out.println("2: Net Income");
        System.out.println("3: Highest Quantity Sold");
        System.out.println("4: Highest Net Income");
        System.out.println("0: Exit System");

        System.out.print("Enter Your Choose: ");
        selection=input.nextInt();

        if (selection==1){
            MethodGross();

        }
        if (selection==2){
            MethodNet(); 
        }
        if (selection==3){
            MethodQuantity();

        }
        if (selection==4){
            MethodIncome();

        }
        if (selection==0){
            System.exit(0);            
        }


    }



    static void MethodGross(){
        int GrossMicroOctober=MicrowaveSellingPrice*QuantitySoldArry[0];
        int GrossMicroNovember=MicrowaveSellingPrice*QuantitySoldArry[1];
        int GrossMicroDecember=MicrowaveSellingPrice*QuantitySoldArry[2];      
        int GrossJuicerOctober=JuicerSellingPrice*QuantitySoldArry[3];
        int GrossJuicerNovember=JuicerSellingPrice*QuantitySoldArry[4];
        int GrossJuicerDecember=JuicerSellingPrice*QuantitySoldArry[5];        
        int GrossMuliCookerOctober=CookerSellingPrice*QuantitySoldArry[6];
        int GrossMuliCookerNovember=CookerSellingPrice*QuantitySoldArry[7];
        int GrossMuliCookerDecember=CookerSellingPrice*QuantitySoldArry[8];int GrossOvenOctober=OvenSellingPrice*QuantitySoldArry[6];
        int GrossOvenNovember=OvenSellingPrice*QuantitySoldArry[7];
        int GrossOvenDecember=OvenSellingPrice*QuantitySoldArry[8];int GrossMicroTotal=GrossMicroOctober+GrossMicroNovember+GrossMicroDecember;
        int GrossJuicerTotal=GrossJuicerOctober+GrossJuicerNovember+GrossJuicerDecember;
        int GrossMuliCookerTotal=GrossMuliCookerOctober+GrossMuliCookerNovember+GrossMuliCookerDecember;
        int GrossOvenTotal=GrossOvenOctober+GrossOvenNovember+GrossOvenDecember;


        System.out.println("Microwave Gross Income in October = "+GrossMicroOctober);
        System.out.println("Microwave Gross Income in November = "+GrossMicroNovember);
        System.out.println("Microwave Gross Income in December = "+GrossMicroDecember);
        System.out.println("Microwave Gross Income in 3 months = "+GrossMicroTotal);
        System.out.println("");

        System.out.println("Juicer Gross Income in October = "+GrossJuicerOctober);
        System.out.println("Juicer Gross Income in November = "+GrossJuicerNovember);
        System.out.println("Juicer Gross Income in December = "+GrossJuicerDecember);
        System.out.println("Juicer Gross Income in 3 months = "+GrossJuicerTotal);
        System.out.println("");

        System.out.println("Multy Cooker Gross Income in October = "+GrossMuliCookerOctober);
        System.out.println("MultyCooker Gross Income in November = "+GrossMuliCookerNovember);
        System.out.println("Multy Cooker Gross Income in December = "+GrossMuliCookerDecember);
        System.out.println("Multy Cooker Gross Income in 3 months = "+GrossMuliCookerTotal);
        System.out.println("");

        System.out.println("Oven Gross Income in October = "+GrossOvenOctober);
        System.out.println("Oven Gross Income in November = "+GrossOvenNovember);
        System.out.println("Oven Gross Income in December = "+GrossOvenDecember);
        System.out.println("Oven Gross Income in 3 months = "+GrossOvenTotal);
        System.out.println("");

        System.out.println("Select a number to display:");

        System.out.println("1: Gross Income");
        System.out.println("2: Net Income");
        System.out.println("3: Highest Quantity Sold");
        System.out.println("4: Highest Net Income");
        System.out.println("0: Exit System");

        System.out.print("Enter Your Choose: ");
        selection=input.nextInt();

        if (selection==1){
            MethodGross();

        }
        if (selection==2){
            MethodNet(); 
        }
        if (selection==3){
            MethodQuantity();

        }
        if (selection==4){
            MethodIncome();

        }
        if (selection==0){
            System.exit(0);            
        }     


    } 

    static void MethodNet(){
        int NetMicroOctober=MicrowaveNetPerIntem*QuantitySoldArry[0];
        int NetMicroNovember=MicrowaveNetPerIntem*QuantitySoldArry[1];
        int NetMicroDecember=MicrowaveNetPerIntem*QuantitySoldArry[2];        
        int NetMicroTotal=NetMicroOctober+NetMicroNovember+NetMicroDecember;

        int NetJuicerOctober=JuicerNetPerIntem*QuantitySoldArry[3];
        int NetJuicerNovember=JuicerNetPerIntem*QuantitySoldArry[4];
        int NetJuicerDecember=JuicerNetPerIntem*QuantitySoldArry[5];        
        int NetJuicerTotal=NetJuicerOctober+NetJuicerNovember+NetJuicerDecember;

        int NetMuliCookerOctober=CookerNetPerItem*QuantitySoldArry[6];
        int NetMuliCookerNovember=CookerNetPerItem*QuantitySoldArry[7];
        int NetMuliCookerDecember=CookerNetPerItem*QuantitySoldArry[8];
        int NetMuliCookerTotal=NetMuliCookerOctober+NetMuliCookerNovember+NetMuliCookerDecember;

        int NetOvenOctober=OvenNetPerItem*QuantitySoldArry[6];
        int NetOvenNovember=OvenNetPerItem*QuantitySoldArry[7];
        int NetOvenDecember=OvenNetPerItem*QuantitySoldArry[8];
        int NetOvenTotal=NetOvenOctober+NetOvenNovember+NetOvenDecember;

        System.out.println("Microwave Net Income in October = "+NetMicroOctober);
        System.out.println("Microwave Net Income in November = "+NetMicroNovember);
        System.out.println("Microwave Net Income in December = "+NetMicroDecember);
        System.out.println("Microwave Net Income in 3 months = "+NetMicroTotal);
        System.out.println("");

        System.out.println("Juicer Net Income in October = "+NetJuicerOctober);
        System.out.println("Juicer Net Income in November = "+NetJuicerNovember);
        System.out.println("Juicer Net Income in December = "+NetJuicerDecember);
        System.out.println("Juicer Net Income in 3 months = "+NetJuicerTotal);
        System.out.println("");

        System.out.println("Multy Cooker Net Income in October = "+NetMuliCookerOctober);
        System.out.println("MultyCooker Net Income in November = "+NetMuliCookerNovember);
        System.out.println("Multy Cooker Net Income in December = "+NetMuliCookerDecember);
        System.out.println("Multy Cooker Net Income in 3 months = "+NetMuliCookerTotal);
        System.out.println("");

        System.out.println("Oven Net Income in October = "+NetOvenOctober);
        System.out.println("Oven Net Income in November = "+NetOvenNovember);
        System.out.println("Oven Net Income in December = "+NetOvenDecember);
        System.out.println("Oven Net Income in 3 months = "+NetOvenTotal);
        System.out.println("");

        System.out.println("Select a number to display:");

        System.out.println("1: Gross Income");
        System.out.println("2: Net Income");
        System.out.println("3: Highest Quantity Sold");
        System.out.println("4: Highest Net Income");
        System.out.println("0: Exit System");

        System.out.print("Enter Your Choose: ");
        selection=input.nextInt();

        if (selection==1){
            MethodGross();

        }
        if (selection==2){
            MethodNet(); 
        }
        if (selection==3){
            MethodQuantity();

        }
        if (selection==4){
            MethodIncome();

        }
        if (selection==0){
            System.exit(0);            
        }
    }

    static void MethodQuantity(){

            int QuantityArray[] = new int[4];
            QuantityArray[0]=QuantitySoldArry[0]+QuantitySoldArry[1]+QuantitySoldArry[2];
            QuantityArray[1]=QuantitySoldArry[3]+QuantitySoldArry[4]+QuantitySoldArry[5];
            QuantityArray[2]=QuantitySoldArry[6]+QuantitySoldArry[7]+QuantitySoldArry[8];
            QuantityArray[3]=QuantitySoldArry[9]+QuantitySoldArry[10]+QuantitySoldArry[11];

            for (int i = 0; i < QuantityArray.length; i++) 
            {
                if(max < QuantityArray[i])
                {
                   max = QuantityArray[i];
                   if (i==0 ){
                       Item="Microwave";
                   }

                   if (i==1){
                       Item="Juicer";
                   }

                   if (i==2){
                       Item="Multipurpose cooker";
                   }

                   if (i==3){
                       Item="Oven";
                   }
                }
            }

            System.out.println("The highest number of quantiry sold:");
            System.out.println("Item: "+Item+"          Quantity: "+max);

            System.out.println("Select a number to display:");

        System.out.println("1: Gross Income");
        System.out.println("2: Net Income");
        System.out.println("3: Highest Quantity Sold");
        System.out.println("4: Highest Net Income");
        System.out.println("0: Exit System");

        System.out.print("Enter Your Choose: ");
        selection=input.nextInt();

        if (selection==1){
            MethodGross();

        }
        if (selection==2){
            MethodNet(); 
        }
        if (selection==3){
            MethodQuantity();

        }
        if (selection==4){
            MethodIncome();

        }
        if (selection==0){
            System.exit(0);            
        }
    }

    static void MethodIncome(){

        int NetMicroOctober=MicrowaveNetPerIntem*QuantitySoldArry[0];
        int NetMicroNovember=MicrowaveNetPerIntem*QuantitySoldArry[1];
        int NetMicroDecember=MicrowaveNetPerIntem*QuantitySoldArry[2];        
        int NetMicroTotal=NetMicroOctober+NetMicroNovember+NetMicroDecember;

        int NetJuicerOctober=JuicerNetPerIntem*QuantitySoldArry[3];
        int NetJuicerNovember=JuicerNetPerIntem*QuantitySoldArry[4];
        int NetJuicerDecember=JuicerNetPerIntem*QuantitySoldArry[5];        
        int NetJuicerTotal=NetJuicerOctober+NetJuicerNovember+NetJuicerDecember;

        int NetMuliCookerOctober=CookerNetPerItem*QuantitySoldArry[6];
        int NetMuliCookerNovember=CookerNetPerItem*QuantitySoldArry[7];
        int NetMuliCookerDecember=CookerNetPerItem*QuantitySoldArry[8];
        int NetMuliCookerTotal=NetMuliCookerOctober+NetMuliCookerNovember+NetMuliCookerDecember;

        int NetOvenOctober=OvenNetPerItem*QuantitySoldArry[6];
        int NetOvenNovember=OvenNetPerItem*QuantitySoldArry[7];
        int NetOvenDecember=OvenNetPerItem*QuantitySoldArry[8];
        int NetOvenTotal=NetOvenOctober+NetOvenNovember+NetOvenDecember;


        int NetArray[] = new int[4];
            NetArray[0]=NetMicroTotal;
            NetArray[1]=NetJuicerTotal;
            NetArray[2]=NetMuliCookerTotal;
            NetArray[3]=NetOvenTotal;

            for (int i = 0; i < NetArray.length; i++) 
            {
                if(max < NetArray[i])
                {
                   max = NetArray[i];
                   if (i==0 ){
                       Item="Microwave";
                   }

                   if (i==1){
                       Item="Juicer";
                   }

                   if (i==2){
                       Item="Multipurpose cooker";
                   }

                   if (i==3){
                       Item="Oven";
                   }
                }
            }

            System.out.println("The Highest Net Income Of 3 Months:");
            System.out.println("Item: "+Item+"          Net Income: "+max);

            System.out.println("Select a number to display:");

        System.out.println("1: Gross Income");
        System.out.println("2: Net Income");
        System.out.println("3: Highest Quantity Sold");
        System.out.println("4: Highest Net Income");
        System.out.println("0: Exit System");

        System.out.print("Enter Your Choose: ");
        selection=input.nextInt();

        if (selection==1){
            MethodGross();

        }
        if (selection==2){
            MethodNet(); 
        }
        if (selection==3){
            MethodQuantity();

        }
        if (selection==4){
            MethodIncome();

        }
        if (selection==0){
            System.exit(0);            
        }

    }

}

Edited 4 Years Ago by pritaeas: Moved.

i meant now i am using the normal display because i am using scanner rite.....i want dialog box using joption but when i change that...there are syntax error....

@alanso:
Please try to be sensible. You have told us that you have "a lot of errors" in some code that you haven't posted. How do you think anyone can possibly help you with unknown errors in unknown code? In your next post you need to post the exact complete code that is giving you problems and the exact complete text of any error messages (not just your own short summary of what yo uthnk they mean).
Until you do that, nobody will be able to help you.

Edited 4 Years Ago by JamesCherrill

ok sorry i have figured out how to do....the problem i am having now is when i run...n display for the monthly sales...it is not inline...it run away even after i insert /t...

 String[]product={"Microwave", "Juicer ", "Multipurpose\ncooker ","Oven "};

String[]month={"October","November","December"};

//declaration
int[]cost={750,380,150,250};
int[]price={1388,650,366,479};
int [][]quantity=new int[4][3];
boolean input=false;
char cont='y';

for (int i=0;i<quantity.length;i++){
for (int j=0;j<quantity[i].length;j++){
//error handling until user enter all the correct input.
do{
try{
quantity[i][j]=Integer.parseInt
(JOptionPane.showInputDialog("Please enter the quatity of sales for "
+"the following products.\n"+   
"Product: "+product[i]+"\nMonth: "+month[j]));
break;
}
catch(Exception e){ 
JOptionPane.showMessageDialog (null,"Invalid! Please enter "+
"again.","Error",

JOptionPane.ERROR_MESSAGE);
}
}while(!input);
}
}

while (cont=='y'){
int selection = Integer.parseInt 
(JOptionPane.showInputDialog("Please select the "+
"the calculation / this is the result:"+
"\n1. Gross income"+
"\n2. Net income"+
"\n3. Highest quantity sold of product within 3 months"+
"\n4. Highest net income of product within 3 months"+
"\n5. Exit the system"));

//case study
switch (selection){
case 1:
gross_income(quantity,price,product,month);
break;
case 2:
net_income(quantity,cost,price,product,month);
break;
case 3:
highest_quantity(product,quantity);
break;
case 4:
net_income(product,quantity,cost,price);
break;
case 5:
JOptionPane.showMessageDialog(null, "System Exit.",
"MESSAGE",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
default:
JOptionPane.showMessageDialog(null, "Invalid operation!",
"ERROR MESSAGE", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,"Please try again.");
break;
}
}
}

public static void gross_income
(int[][]quantity,int[]price,String[]product,String[]month){
int[][]gross_per_month=new int [4][3];
int[]gross_month=new int [4];

for(int i=0;i<gross_per_month.length;i++){
for(int j=0;j<gross_per_month[i].length;j++){
gross_per_month[i][j]+=quantity[i][j]*price[i];
gross_month[i]+=gross_per_month[i][j];
}
}

System.out.println("\nGross income for each product for each month "+
" and three months (RM)");
System.out.println("-----------------------------------------------"+
"------------------------------------------");
System.out.print("Product\t\t\t");
for (int a=0;a<month.length;a++){
System.out.print(month[a]+"\t\t");
}
System.out.println("\tTotal");
System.out.println("-----------------------------------------------"+
"------------------------------------------");
for (int b=0;b<gross_per_month.length;b++){
System.out.print(product[b]+"\t\t");
for (int c=0;c<gross_per_month[b].length;c++){
System.out.print(gross_per_month[b][c]+"\t\t");
}
System.out.print("\t"+gross_month[b]);
System.out.println("\n");
}
System.out.println("-----------------------------------------------"+
"------------------------------------------");
}

public static void net_income(int[][]quantity, int[]cost,int[]price,
String[]product,String[]month){
int[][]net_per_month=new int[4][3];
int[]net_month=new int[4];

for(int i=0;i<net_per_month.length;i++){
for(int j=0;j<net_per_month[i].length;j++){
net_per_month[i][j]+=quantity[i][j]*(price[i]-cost[i]);
net_month[i]+=net_per_month[i][j];
}
}

System.out.println("\nNet income for each product for each month and "+
" three months (RM)");
System.out.println("-----------------------------------------------"+
"------------------------------------------");
System.out.print("Product\t\t\t");
for (int p=0;p<month.length;p++){
System.out.print(month[p]+"\t\t");
}
System.out.println("\tTotal");
System.out.println("-----------------------------------------------"+
"------------------------------------------");
for (int q=0;q<net_per_month.length;q++){
System.out.print(product[q]+"\t\t");
for (int r=0;r<net_per_month[q].length;r++){
System.out.print(net_per_month[q][r]+"\t\t");
}
System.out.print("\t"+net_month[q]);
System.out.print("\n");
}
System.out.println("-----------------------------------------------"+
"------------------------------------------");
}

public static void highest_quantity(String[]product,int[][]quantity){
int [] total = new int [4];
int maxNum=0;
String maxPro="";

for (int i=0; i<quantity.length;i++){
for(int j=0;j<quantity[i].length;j++){
total[i]+=quantity[i][j];
if (total[i]>maxNum){
maxNum=total[i];
maxPro=product[i];
}
}
}
JOptionPane.showMessageDialog(null, "The product with highest "
+" quantity sold within 3 months is "+maxPro+
"\nThe number of quantity sold of this product"+
" is "+maxNum+".");

}

public static void net_income(String[]product, int[][]quantity, 
int[]cost,int[]price){
int maxNum=0;
String maxPro="";
int [][]net_per_month=new int[4][3];
int []net_month=new int [4];

for (int i=0;i<quantity.length;i++){
for(int j=0;j<quantity[i].length;j++){
net_per_month[i][j]+=quantity[i][j]*(price[i]-cost[i]);
net_month[i]+=net_per_month[i][j];
if(net_month[i]>maxNum){
maxNum=net_month[i];
maxPro=product[i];
}
}
}
JOptionPane.showMessageDialog(null, "The product with highest net "+
" income within 3 months is "+maxPro+
"\nThe income of the product is RM "+maxNum+".");
}
}

ok sorry i have figured out how to do....the problem i am having now is when i run...n display for the monthly sales...it is not inline...it run away even after i insert /t...

this is still very ague. you have figured out how to do ... how to do what?
and the problem now "it is not inline" what is not inline? what do you get and how do you expect to get it?

This article has been dead for over six months. Start a new discussion instead.