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 2
Oldest  Newest  Rating
+1 Jay Deshaun · February 16, 2015
I think he means the "default" case/statement within the switch statement.
0 Developer John · February 20, 2015
Okay, so this is what I currently have, but for some reason, once I want to use an option for the second time around, it invokes the while loop, which isn't supposed to happen:

Main Class:


import java.util.Scanner;

public class Bank{

public static void main(String args[]){
Bank2 b2 = new Bank2();
b2.setAccount();

}
}


Subclass:


import java.util.Scanner;

class Bank2{

public String fn, sn, ac_no, type, withdraw, deposit, deposit3, details;
public double deposit2, withdraw2;
public double balance;
public double newBalance = balance + deposit2;
Scanner x = new Scanner(System.in);

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

while(!fn.matches("[a-zA-Z]+") || !fn.equalsIgnoreCase("d")){
System.out.println("Invalid first name! Please retry.");
fn = x.nextLine();

}

if(!fn.equalsIgnoreCase("")){
System.out.println("The user's first name has been sucessfully entered!\n");

}

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

while(!sn.matches("[a-zA-Z]+")){
System.out.println("Invalid last name! Please retry.");
sn = x.nextLine();

}

if(!fn.equalsIgnoreCase("")){
System.out.println("The user's last name has been sucessfully entered!\n");

}

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

while(!ac_no.matches("[0-9]+")){
System.out.println("Invalid account number! Please retry.");
ac_no = x.nextLine();

}

if(!fn.equalsIgnoreCase("")){
System.out.println("The user's account number has been sucessfully entered!\n");

}

//Account Type
System.out.println("Enter the account type(current or savings).");
type = x.nextLine();

while(type.equalsIgnoreCase("") || !type.equalsIgnoreCase("current") && !type.equalsIgnoreCase("savings")){
System.out.println("Invalid account type! Please retry.");
type = x.nextLine();

}

if(type.equalsIgnoreCase("savings") || !type.equalsIgnoreCase("current")){
System.out.println("The account type has been successfully entered!\n");
System();

}

}

void Withdraw(){
System.out.println("Would you like to make a withdraw(yes or no)?\n");
withdraw = x.nextLine();

while(withdraw.equalsIgnoreCase("") || withdraw.equalsIgnoreCase("b")){
System.out.println("Invalid response! Please retry.");
withdraw = x.nextLine();

}

if(withdraw.equalsIgnoreCase("yes") && newBalance0){
System.out.println("What amount would you like to withdraw?\n");
withdraw2 = x.nextDouble();

while(withdraw.equalsIgnoreCase("") || !withdraw.matches("[0-9]+")){
System.out.println("Invalid response! Please retry.");
withdraw = x.nextLine();

}

if(withdraw2 > newBalance){
System.out.println("Not enough balance to withdraw!\n");
System();

}

else if(withdraw2 < newBalance){
System.out.println("Amount withdrawn successfully!\n");
System();

}

}

else if(withdraw.equalsIgnoreCase("no")){
System.out.println("Okay.\n");
System();

}

}

void Deposit(){
//Deposit
System.out.println("Would you like to make a deposit(yes or no)?\n");
deposit = x.nextLine();

while(deposit.equalsIgnoreCase("") || !deposit.equalsIgnoreCase("a")){
System.out.println("Invalid response! Please retry.");
deposit = x.nextLine();

}

if(deposit.equalsIgnoreCase("yes")){
System.out.println("What amount would you like to enter?\n");
deposit2 = x.nextDouble();
System.out.print("Your new balance is: ");
System.out.print(deposit2 + newBalance);
System.out.println("\n");
System();

}

else if(deposit.equalsIgnoreCase("no")){
System.out.println("Okay.\n");
System();

}

}

void Details(){
System.out.println("Would you like to know your details(yes or no)?\n");
details = x.nextLine();

while(details.equalsIgnoreCase("") || !details.equalsIgnoreCase("c")){
System.out.println("Invalid response! Please retry.");
details = x.nextLine();

}

if(details.equalsIgnoreCase("yes")){
System.out.println("Okay, here they are:\n\n" 
+ "Your name is " + fn + " " + sn + ".\n\n"
+ "Your account number is " + ac_no + ".\n\n"
+ "Your account type is " + type + ".\n\n"
+ "Your balance is now " + newBalance + ".\n\n");
System();

}

if(details.equalsIgnoreCase("no")){
System.out.println("Okay.\n");
System();

}

}

void System(){
Scanner y = new Scanner(System.in);
String ch;

System.out.println("Enter your choice:\n");
System.out.println("Press a to make a deposit.");
System.out.println("Press b to make a withdraw.");
System.out.println("Press c for details.");
System.out.println("Press d to reset.");
System.out.println("Enter any value to exit the system.");
ch = y.nextLine();

switch (ch){
case "a":
Deposit();
break;
case "b":
Withdraw();
break;
case "c":
Details();
break;
case "d":
setAccount();
break;
default:
System.out.println("System exited!");
break;
}
}
}
0 Arnab Banerjee · February 17, 2015
No John, 
System.out.println("Enter any value to exit ");


I reckon this statement was unnecessary, switch case statement is necessary///
0 Jay Deshaun · February 19, 2015
Yea, same
I've tried to figure it out while editing it
  • 1
  • 2

Java / Android Development

130,014 followers
About

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

Links
Moderators
Bucky Roberts Administrator