Thursday, December 8, 2011

Code not compiling! Java:plz check code!?

The program is throwing up errors:





import java.io.*;


public class project


{


String cust_name;


int cust_id,account_no,code;


int balance,w,d;


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


public void run()throws IOException


{


do{


System.out.println("enter code");


code=Integer.parseInt(br.readLine());


if(code==5555)


{


getdata();


int ch;


char a='y';


do{


System.out.println("please select what you want to do");


System.out.println("select a choice");


System.out.println("1.withdrawl");


System.out.println("2.deposit");


System.out.println("3.balance enquiry");


System.out.println("4.exit");


System.out.println("enter your choice");


ch=br.read();


switch(ch)


{


case '1':


withdrawl();


break;


case'2':


deposit();


break;


case'3':


showdata();


break;


case'4':


System.out.println("do you want another transaction?");


System.out.println("enter y for yes and n for no");


a=(char)br.read();


break;


default:


System.out.println("you have entered the wrong choice.please try again");


break;


}}


while(!(ch=='n'));


}


else


System.out.println("try again wrong code");


}while(!(code==5555));


}





public void getdata()throws IOException


(


System.out.println("enter customer i.d");


cust_id=Intger.parseInt(br.readLine())鈥?br>

System.out.println("enter cust acc no");


account_no=Integer.parseInt(br.readLin鈥?br>

System.out.println("enter cust name");


cust_name=br.read();


System.out.println("enter balanceamt in acc");


balance=Integer.parseInt(br.readLine()鈥?br>




}





public void withdrawl()throws IOException


{


System.out.println("Enter amt to be withdrawn ( %26lt; "+balance+ " ) ");


w=Integer.parseInt(br.readLine());


if( w%26lt; balance)


{


balance-=w;


System.out.println(" Amt has been withdrawn");


System.out.println(" New balance is : " + balance);


}


else


{


System.out.println(" Sorry! Amt cannot be withdrawn");


}


}





public void deposit()throwsIOException


{


System.out.println("enter amt to be deposited");


String s2=br.readLine();


d=Integer.parseInt(s2);


balance+=d;


System.out.println("amt has been deposited");


System.out.println("new balance is"+balance);


}


public void showdata()throws IOException


{


System.out.println("cust name:"+cust_name);


System.out.println{"cust id"+cust_id);





System.out.println("cust acc no"+account_no);





System.out.println("balance amount in acc"+balance);


}}





This is a simple program to withdraw or deposit money in an account.


In the line public void getdata() throws IOException,


it says semicolon missing.


Earlier, at school, I compiled the program but during the execution, there was a number format exception in getdata() when the value of w is being taken in.


I need it by next monday. Plz help!!





|||Well it seems you have just copied it from somewhere.


Problems were


1)You have made few spelling mistakes like "Intger" in place of "Integer"


2)You have used "(" in place of "{"


3) You have also used "{" in place of "("


4)You have used br.read() for customer name which will show you TypeCasting error as read() takes integer values so replace it with readLine() ; as you used in other integer value


You can use read() there there wouldnt be any need of Integer.parseInt() thn.








My suggestion for you is please use some IDE like "eclipse" or "IntellJ","BlueJ"or any light wieght IDE where yu can concentrate on Logic rather than worrying about sucha silly spelling mistakes.





Anyways heres the corrected code take a look n compare with your old one





import java.io.*;





public class project


{


String cust_name;





int cust_id , account_no , code;





int balance , w , d;





BufferedReader br = new BufferedReader(new InputStreamReader(System.in));





public void run ( ) throws IOException


{


do


{


System.out.println("enter code");


code = Integer.parseInt(br.readLine());


if ( code == 5555 )


{


getdata();


int ch;


char a = 'y';


do


{


System.out.println("please select what you want to do");


System.out.println("select a choice");


System.out.println("1.withdrawl")鈥?br>

System.out.println("2.deposit");


System.out.println("3.balance enquiry");


System.out.println("4.exit");


System.out.println("enter your choice");


ch = br.read();


switch ( ch )


{


case '1' :


withdrawl();


break;


case '2' :


deposit();


break;


case '3' :


showdata();


break;


case '4' :


System.out.println("do you want another transaction?");


System.out.println("enter y for yes and n for no");


a = (char) br.read();


break;


default :


System.out


.println("you have entered the wrong choice.please try again");


break;


}


} while (!(ch == 'n'));


} else


System.out.println("try again wrong code");


} while (!(code == 5555));


}





public void getdata ( ) throws IOException


{


System.out.println("enter customer i.d");


cust_id = Integer.parseInt(br.readLine());


System.out.println("enter cust acc no");


account_no = Integer.parseInt(br.readLine());


System.out.println("enter cust name");


cust_name = br.readLine();


System.out.println("enter balanceamt in acc");


balance = Integer.parseInt(br.readLine());





}





public void withdrawl ( ) throws IOException


{


System.out.println("Enter amt to be withdrawn ( %26lt; " + balance + " ) ");


w = Integer.parseInt(br.readLine());


if ( w %26lt; balance )


{


balance -= w;


System.out.println(" Amt has been withdrawn");


System.out.println(" New balance is : " + balance);


} else


{


System.out.println(" Sorry! Amt cannot be withdrawn");


}


}





public void deposit ( ) throws IOException


{


System.out.println("enter amt to be deposited");


String s2 = br.readLine();


d = Integer.parseInt(s2);


balance += d;


System.out.println("amt has been deposited");


System.out.println("new balance is" + balance);


}





public void showdata ( ) throws IOException


{


System.out.println("cust name:" + cust_name);


System.out.println("cust id" + cust_id);





System.out.println("cust acc no" + account_no);





System.out.println("balance amount in acc" + balance);


}


}





Hope this solves your issues


Cheers:)

No comments:

Post a Comment