Thread: Snytax error
View Single Post
Old Apr 29th, 2008, 7:46 AM   #10
A.K.Al Shamsi
Programmer
 
A.K.Al Shamsi's Avatar
 
Join Date: Mar 2008
Posts: 35
Rep Power: 0 A.K.Al Shamsi is on a distinguished road
Re: Snytax error

i asked to help from one of my classmate and here is the code

this for the clas which has the operations
 public class Convert{     // Convert class starts
    
    public Integer minute(Integer hr){ // define a varible and pass parameter
        Integer min = hr * 60; // declare minutes with shortcut and the 
        // operation of converting hour to minutes
        return min; // return type of minute 
    }// end of minute
    
    
     public double hour(double min){ // define a varible and  pass parameter min
       double hr = min / 60; // declare minutes with shortcut  and the operation 
       //of converting minutes to hours
        return hr;// return type of hour
    }// end of hour
     
     
          public double hr(double day){// define a varible hour with shortcut 
         // because there is another varible called hour so it should be changed 
         //and pass parameter
        double hr = day * 24  ;//declare hour with shortcut and the operation
        //of converting day to hours
        return hr;// return type of hour
     }// end of hour
          
     
     public double day(double hour){// define a varible and pass parameter
        double day = hour / 24  ;//declare day and the operation 
        //of converting hours to day
        return day;// return type of day
     }// end of day
     
       
         
     public Integer week(Integer yr){// define a varibel week and pass 
        //parameter
       Integer wek = yr*52  ;// decalre week with shortcut and the operation of 
        //converting weeks to years
        return wek;// return type of week
     }//end of week
             
             
      public Integer Day(Integer week ){//define a varible day and pass 
        //parameter
      Integer  Dy = week *7 ;// declare day with shortcut and the operation of 
      //converting week to days
        return Dy; //return type of day
      }// end of day
      
      
      public double week ( double day){
      double week = day / 7;
      return day;
      }
      
              
      
        public double year(double week){// define a varible year and pass 
        //parameter
        double yer = week/52  ;// declare year with shortcut and the operation 
        //of converting year to week 
        return yer;//return type of year
     }// end of year1
        
             
        
        public double yer(double month ){// define a varible year with a  and 
            //pass parameter. because year is declared before year so the name 
            //should be different
        double   yar = month/12;// declate year with shortcut and the operation 
        //of converting months to year
        return yar;// retrun type of year
     }// end of year2
        
        
}// end of the class


and this for main method
 //import java.lang.String and int; 
// import the package to avoid any snytax error
import javax.swing.*;
// import this package for graphical user interface

public class ConvertTest{// the class starts
    
    public static void main(String args[]){// the main mothed starts for executing the programme
        
        Convert test = new Convert ();// creating an object to call for convert class
        
        while(true){// while true starts for looping
        String menu="Enter your Option:\n " ;
        // the menu starts and converting ways of minute, hour, day, year, month, week and year
        String Option1= "1- Convert from Minute to Hour                  2- Convert from Hour to Minute \n";
        String Option2= " 3- Convert from Day to Hour                        4- Convert from Hour to Day \n";
        String Option3= " 5- Convert from Days to Week                    6- Convert from Week to Days \n";
        String Option4= " 7- Convert from Year to Weeks                   8- Convert from Weeks to Year \n";
        String Option5= " 9- Convert from Months to Year                  0- Exit";
        String choose= JOptionPane.showInputDialog(menu + Option1 + Option2+ Option3+ Option4+Option5);
        // to dispaly the menu in input dialog so the user can enter any number from above
        int num = Integer.parseInt(choose);} // to convert string to number
        
while(true){ // while starts
           String Option1 = JOptionPane.showInputDialog("Enter Number to Convert from Minute to Hour"); // dialog box to enter a number
try{// try statement starts
	int y = Integer.parseInt(Option1);//converting from string to number
        
	if (y == 1){// if statement starts and checking of the method
Integer minutes=test.minute(y);//calling the formula  from convert class
JOptionPane.showMessageDialog(null,"Minutes ="+minutes+ " Hours");// display the answer in dialog box
        }//if ends

else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts 
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while



while(true){//while starts
           String Option2 = JOptionPane.showInputDialog("Enter Number toConvert from Hour to Minute"); // dialog box to enter a number
            try{// try statement starts
                int x = Integer.parseInt(Option2);//converting from string to number
	if (x == 2){// if statement starts and checking of the method
 double Hour=test.hour(x);//calling the formula  from convert class
JOptionPane.showMessageDialog(null,"Hours = "+Hour+ " Minutes");// display the answer in dialog box
        }//if ends

else{ // else starts

break;// the programme stops
}} // end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number with this forumal 0.0");// display an error
}}//end of catch and while


while(true){// while starts
          String  Option3 = JOptionPane.showInputDialog("Enter Number to Convert from Day to Hour"); // dialog box to enter a number
try{// try statement starts
int d = Integer.parseInt(Option3);//converting from string to number
	if (d == 3){// if statement starts and checking of the method
        double Day=test.hr(d);//calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Day = "+Day+ " Hours");// display the answer in dialog box
        }//if ends

else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
            String Option4 = JOptionPane.showInputDialog("Enter Number to Convert from Hour to Day");// dialog box to enter a number
            try{// try statement starts
            int h = Integer.parseInt(Option4);//converting from string to number
	if (h == 4){// if statement starts and checking of the method
        double Hour=test.day(h);//calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Hours =  "+ Hour + " Day"); // display the answer in dialog box
        }//if ends

else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
            String Option5 = JOptionPane.showInputDialog("Enter Number to Convert from Days to Week");// dialog box to enter a number
try{// try statement starts
int x = Integer.parseInt(Option5);//converting from string to number
	if (x == 5){// if statement starts and checking of the method
        double week=test.Day(x); //calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Days = "+week+ "Week");// display the answer in dialog box
        }//if ends

else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
           String Option6 = JOptionPane.showInputDialog("Enter Number to Convert from Week to Days");// dialog box to enter a number
try{// try statement starts
 int x = Integer.parseInt(Option6);//converting from string to number
	if (x == 6){// if statement starts and checking of the method
        double week=test.week(x); //calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Weeks "+  week+ " Days");// display the answer in dialog box
        }//if ends
else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
            String Option7 = JOptionPane.showInputDialog("Enter Number to Convert from Year to Weeks");// dialog box to enter a number
try{// try statement starts
int x = Integer.parseInt(Option7);//converting from string to number
	if (x == 7){// if statement starts and checking of the method
                
       double  year=test.week(x);//calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Weeks"+ " " +"years");// display the answer in dialog box
        } //if ends
else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while


while(true){// while starts
            String Option8 = JOptionPane.showInputDialog("Enter Number to Convert from Weeks to Year");// dialog box to enter a number
try{// try statement starts
int x = Integer.parseInt(Option8);//converting from string to number
	if (x == 8){// if statement starts and checking of the method           
       double Hour=test.year(x);//calling the formula  from convert class
        JOptionPane.showMessageDialog(null,"Years"+ " "+" Weeks");// display the answer in dialog box
        } //if ends
else{// else starts
break;// the programme stops
}}// end of else  and try
catch (Exception e){// catch starts
	JOptionPane.showMessageDialog(null,"Enter a number");// display an error
}}//end of catch and while

while(true){// the while loop starts
            String Option9 = JOptionPane.showInputDialog("Enter Number to Convert from Months to Year");// input number to get the answer
try{// the validation of try starts
int x = Integer.parseInt(Option9);//convert string into a number
	if (x == 9){// if statement starts to check the value
        double month=test.yer(x);// calling the formula from the class
        JOptionPane.showMessageDialog(null,"Months"+" " +"Year");
        }
else{// doing another thing
break;// the programme stops
}// end else
}//end try
catch (Exception e){// the exception starts
	JOptionPane.showMessageDialog(null,"Enter a Number with this format 0.0");// display a message when the format is wrong
}//end exception
}//end of the while loop
  
        String Option0=JOptionPane.showInputDialog("Enter Number to Exit from The Programme");
        int z=Integer.parseInt(Option0);
            if (z == 0){// 0 is the number of exiting for the programme
                   break; 
            }// to stop the programme from running
        
    }// end main method
 } //end class


the last error disspeared but i have error in last brea which is this :

  String Option0=JOptionPane.showInputDialog("Enter Number to Exit from The Programme");
        int z=Integer.parseInt(Option0);
            if (z == 0){// 0 is the number of exiting for the programme
                   break; 
            }// to stop the programme from running
the error says"breaks outside switch or loop"

do you have any idea about this error and how could it be solved??
A.K.Al Shamsi is offline   Reply With Quote