What is wrong here (Please check the code)

+3 Arnab Banerjee · February 14, 2015
import java.util.Scanner;
public class bank {
String fn,sn,ac_no,type;
double balance;
Scanner x = new Scanner(System.in);


void setAccount(){
try{
System.out.println("Enter user's first name ");
fn = x.nextLine();
if (fn.contains(null))


}

catch(Exception e ){
System.out.println("Please enter first name correctly");



try{
System.out.println("Enter user's second name ");
sn = x.nextLine();
if(sn.contains(null)){

}
}
catch(Exception e){
System.out.println("Please enter second name correctly");
setAccount();
}
try{
System.out.println("Enter user's account no. ");
ac_no = x.nextLine();
if(ac_no.contains(null)){

}
}
catch(Exception e){
System.out.println("Please enter account No. correctly");
}
System.out.println("Enter account type ");
type = x.nextLine();
if(type.equals("Savings") || type.equals("savings")){

}
else if(type.equals("Current" ) || type.equals("current")) {

}
else
System.out.println("Not correct account type");
type = "NOT SET";

if(type.equals("NOT SET"))
setAccount();

System.out.println("Enter the amount you want to deposit initially ");
balance = x.nextDouble();
if(type.equals("NOT SET")){
System.out.println("Not correct account type to deposit money");
balance = 0;
setAccount();
}
if(balancebalance){
System.out.println("Not enough balance to withdraw ");
b = 0;
}
else
System.out.println("The amount withdrawn " + b);
balance = balance -b ;
display();
}

void display(){

System.out.println("Your balance is " +balance);
}

void details(){
System.out.println("Your name is " +fn + " " +sn);
System.out.println("Your account no. is " +ac_no);
System.out.println("Your account type is " + type);
System.out.println("Your balance is " + balance);
}

public static void main(String args[]){
Scanner y = new Scanner(System.in);
bank b1 = new bank();
b1.setAccount();

int ch;

while(true){
System.out.println("Enter your choice: ");
System.out.println("");
System.out.println("Press 1 to deposit");
System.out.println("Press 2 to withdraw");
System.out.println("Press 3 for details");
System.out.println("Press 4 to Reset ");
System.out.println("Enter any value to exit ");

ch = y.nextInt();
switch (ch){

case 1:
b1.depositAcc();
break;
case 2:
b1.withdrAcc();
break;
case 3:
b1.details();
break;
case 4:
b1.setAccount();
break;
default:
System.out.println("Enter correct choice ");
break;

  }

  }
}
}


It is not taking any data ?? 

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
+1 Developer John · February 14, 2015
Okay. First off, are you using the Eclipse IDE? Secondly, did you know this method exists:


else if(type.equalsIgnoreCase("Current")){

This method checks if the variable is equal to a String, disregarding the capitalization. 
+1 Jay Deshaun · February 14, 2015
Got to give me a while on this one...
There's kind of too much errors in this one.
+1 Developer John · February 14, 2015
No, lets just go through it piece by piece, it's much easier.
+1 Arnab Banerjee · February 14, 2015
Okay .. :) 
+1 Jay Deshaun · February 14, 2015
Ok, so instead of calling Accounts again and again, you should just use a while loop until they input something for either the names, account type, account number, etc...

That would be a huge memory consumption and waste of time for the person them selves.

Here's your code with a lot of comments that needs filling and some functions need to be created:
import java.util.Scanner;
public class bank {
String fn,sn,ac_no,type;
double balance=0;
Scanner x = new Scanner(System.in);

void setAccount(){
//First Name
System.out.println("Enter user's first name: ");
fn = x.nextLine();
while(fn.equalsIgnoreCase(""))
fn = x.nextLine();

//if(fn.equalsIgnoreCase(""))
// System.out.println("Please enter first name correctly");

//Second Name
System.out.println("Enter user's second name ");
sn = x.nextLine();
while(sn.equalsIgnoreCase(""))
sn = x.nextLine();

//if(sn.equalsIgnoreCase(""))
// System.out.println("Please enter second name correctly");

//Account #
System.out.println("Enter user's account no. ");
ac_no = x.nextLine();
while(ac_no.equalsIgnoreCase(""))
ac_no = x.nextLine();

//if(ac_no.equalsIgnoreCase(""))
// System.out.println("Please enter account No. correctly");

//Account Type
System.out.println("Enter account type (Current or Savings) ");
type = x.nextLine();
while(type.equalsIgnoreCase("") || !type.equalsIgnoreCase("current") || !type.equalsIgnoreCase("savings"))
type = x.nextLine();

if(type.equalsIgnoreCase("savings"))
System.out.println("");
else if(type.equalsIgnoreCase("current"))
System.out.println("");

//Deposit
if(balance<=0){
System.out.println("Not enough balance to withdraw");
display();
return; //end the rest of the script
}
System.out.println("Enter the amount you want to deposit initially ");
double deposit = x.nextDouble();
if(deposit>balance)
System.out.println("Not enough to withdraw!");
else
System.out.println("The amount withdrawn " + deposit);
balance = balance - deposit;

display();
}

void display(){
System.out.println("Your balance is " +balance);
}

void details(){
System.out.println("Your name is " +fn + " " +sn);
System.out.println("Your account no. is " +ac_no);
System.out.println("Your account type is " + type);
System.out.println("Your balance is " + balance);
}

public static void main(String args[]){
Scanner y = new Scanner(System.in);
bank b1 = new bank();
b1.setAccount();

int ch;

while(true){
System.out.println("Enter your choice: \n\n");
System.out.println("Press 1 to deposit");
System.out.println("Press 2 to withdraw");
System.out.println("Press 3 for details");
System.out.println("Press 4 to Reset ");
System.out.println("Enter any value to exit ");

ch = y.nextInt();
switch (ch){

case 1:
//b1.depositAcc();
break;
case 2:
//b1.withdrAcc();
break;
case 3:
b1.details();
break;
case 4:
b1.setAccount();
break;
default:
System.out.println("Enter correct choice ");
break;
 }

 }
}
}
+1 Developer John · February 15, 2015
What is the point in the entries of 1-4 or any value to exit?
+1 Developer John · February 16, 2015
Using Jay Deshaun's edit of your code, what is the point in this Arnab Banerjee:


while(true){
System.out.println("Enter your choice: \n\n");
System.out.println("Press 1 to deposit");
System.out.println("Press 2 to withdraw");
System.out.println("Press 3 for details");
System.out.println("Press 4 to Reset ");
System.out.println("Enter any value to exit ");

ch = y.nextInt();
switch (ch){

case 1:
//b1.depositAcc();
break;
case 2:
//b1.withdrAcc();
break;
case 3:
b1.details();
break;
case 4:
b1.setAccount();
break;
default:
System.out.println("Enter correct choice ");
break;
}

}
}
}
+1 Arnab Banerjee · February 16, 2015
Hmm. the last statement is unnecessary  :P 
+1 Developer John · February 16, 2015
Which statement? The switch statement?
+1 Jay Deshaun · February 16, 2015
I think he means the "default" case/statement within the switch statement.
  • 1
  • 2

Java / Android Development

106,967 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator