BankTransaction cannot be resolved to a type

Associate
Joined
8 Jan 2009
Posts
1,492
Location
Northern Ireland
Can't get my head round this. It's either a typo or a problem, can anybody have a look.

import javax.swing.JOptionPane;
public class classpractice7_1 {
public static void main(String[] args) {
String response;
String moreBankingBusiness;


moreBankingBusiness = JOptionPane.showInputDialog
( "Do you want to do some banking?" );
moreBankingBusiness = moreBankingBusiness.toUpperCase();
while (moreBankingBusiness.equals ("YES")){
response = JOptionPane.showInputDialog
( "What would you like to do?" +
"(1=Deposit, 2=Withdraw, 3=Get Balance)");
if (response == null)
{
JOptionPane.showMessageDialog
(null, "You clicked on the Cancel Button");
System.exit (0);
}
else
if (response.equals(""))
{
JOptionPane.showMessageDialog
(null, "You must make an entry in the InputBox");
System.exit (0);
}
else
if (Integer.parseInt(response) < 1 | Integer.parseInt(response) > 3)
{
JOptionPane.showMessageDialog
(null, response + " - is not a valid student type");
System.exit (0);
}
if (Integer.parseInt (response) == 1){
BankTransaction transaction = new BankTransaction();
transaction.makeDeposit();
}
if (Integer.parseInt (response) == 2){
BankTransaction transaction = new BankTransaction();
transaction.makeWithdrawal();
}
if (Integer.parseInt (response) == 3){
BankTransaction transaction = new BankTransaction();
transaction.getBalance();
}
moreBankingBusiness = JOptionPane.showInputDialog
( "Do you have more banking business?" );
moreBankingBusiness= moreBankingBusiness.toUpperCase();
} // end of while

JOptionPane.showMessageDialog
(null, "Thanks for banking with us!");
}
}
 
Associate
Joined
24 Jun 2008
Posts
1,168
But if BankTransaction isn't a class it wont have the makeWithdrawal() methods or any functionality. Putting 'String BankTransaction' wont help.

I do like the way you've copied and pasted some other code though :)

Code:
"What would you like to do?" +
"(1=Deposit, 2=Withdraw, 3=Get Balance)"

...

response + " - is not a valid student type");
 
Last edited:
Associate
OP
Joined
8 Jan 2009
Posts
1,492
Location
Northern Ireland
I do like the way you've copied and pasted some other code though

Code:

"What would you like to do?" +
"(1=Deposit, 2=Withdraw, 3=Get Balance)"

...

response + " - is not a valid student type");

na, never copied and pasted that, that's mine. BankTransactions is a class, that's why I put the other methods in, ie getBalance etc. But it should work.
 
Associate
Joined
24 Jun 2008
Posts
1,168
I just meant that you prompt for banking stuff and then respond with not a valid student type.

In that case back to slylittlefox's question:
"Where do you define the class BankTransaction?? "
 
Associate
OP
Joined
8 Jan 2009
Posts
1,492
Location
Northern Ireland
I think I was pushing my luck with the 'BankTransactions', were I would be better off just doing this, I know this works.

if (Integer.parseInt(response) == 1) {
makeDeposit();
}
if (Integer.parseInt(response) == 2) {
makeWithdrawal();
}
if (Integer.parseInt(response) == 3) {
getBalance();
}
 
Associate
OP
Joined
8 Jan 2009
Posts
1,492
Location
Northern Ireland
This is an program i did a few weeks ago, and this compiles with no problems,

import javax.swing.JOptionPane;

/*
* Created on Sep 3, 2009
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author Robin Bredin
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import javax.swing.JOptionPane;
public class classpracyice6_2 {
static double balance = 0;
static double newBalance = 0;
static double adjustment = 0;

public static void main(String[] args) {
String response;
String moreBanKingBusiness;
moreBanKingBusiness = JOptionPane.showInputDialog
( "DO you want to do some banking?" );
moreBanKingBusiness = moreBanKingBusiness.toUpperCase();
while (moreBanKingBusiness.equals ("YES")){
response = JOptionPane.showInputDialog
( "What would you like to do?, (1=Deposit, 2=Withdraw, 3=Get Balance)");
if (response == null)
{
JOptionPane.showMessageDialog
(null, "You clicked on the Cancel button");
System.exit (0);
}
else
if (response.equals(""))
{
JOptionPane.showMessageDialog
(null, "You must make an entry in the InputBox");
System.exit (0);
}
else
if (Integer.parseInt(response) < 1 | Integer.parseInt(response) > 3)
{
JOptionPane.showMessageDialog
(null, response + " - is not a valid banking function");
System.exit (0);
}

if (Integer.parseInt(response) == 1) {
makeDeposit();
}
if (Integer.parseInt(response) == 2) {
makeWithdrawal();
}
if (Integer.parseInt(response) == 3) {
getBalance();
}

moreBanKingBusiness = JOptionPane.showInputDialog
( "Do you have more banking buiness?" );
moreBanKingBusiness = moreBanKingBusiness.toUpperCase();
} //end of while loop
JOptionPane.showMessageDialog(null, "Thanks for banking with us!");
System.exit (0);
} // end of main

private static void makeDeposit(){
adjustment = Double.parseDouble
(JOptionPane.showInputDialog( "Enter the Deposit Amount" ));
newBalance = balance + adjustment;
JOptionPane.showMessageDialog
(null, "*** My National Bank ***\n\n" +
"Old Balance is: " + balance + "\n" +
"Adjustment is: +" + adjustment + "\n" +
"New Balance is: " + newBalance + "\n");
balance = newBalance;
}


private static void makeWithdrawal() {
adjustment = Double.parseDouble
(JOptionPane.showInputDialog( "Enter the Withdrawal Amount" ));
newBalance = balance - adjustment;
JOptionPane.showMessageDialog
(null, "*** My National Bank ***\n\n" +
"Old Balance is: " + balance + "\n" +
"Adjustment is: -" + adjustment + "\n" +
"New Balance is: " + newBalance + "\n");
balance = newBalance;
}



private static void getBalance(){
JOptionPane.showInputDialog
(null, "*** My National Bank ***\n\n" +
"Your Current Balance is: " + balance );
}
}//
 
Associate
Joined
24 Jun 2008
Posts
1,168
OK, so I don't do java but in your original you will need something like this:

Code:
public class BankTransaction {
  public static void makeDeposit() {
    //make deposit stuff
  }
  public static void makeWithdrawal() {
    //makeWithdrawal stuff
  }
  public static void getBalance() {
    //getBalance stuff
  }
}

Do you have something like that?
 
Associate
OP
Joined
8 Jan 2009
Posts
1,492
Location
Northern Ireland
Hi There is a few errors lines under Banktransactions for withdrawal

Code:
import javax.swing.JOptionPane;
public class classpractice7_1 {
          public static void main(String[] args) {
          	String response;
          	String moreBankingBusiness;
          	
          	
          	moreBankingBusiness = JOptionPane.showInputDialog
			  ( "Do you want to do some banking?" );
          	moreBankingBusiness = moreBankingBusiness.toUpperCase();
          	while (moreBankingBusiness.equals ("YES")){
          		response = JOptionPane.showInputDialog
				( "What would you like to do?" +
					"(1=Deposit, 2=Withdraw, 3=Get Balance)");
          	if (response == null)
          	{
          		JOptionPane.showMessageDialog
				   (null, "You clicked on the Cancel Button");
          		System.exit (0);
          	}
          	else
          	if (response.equals(""))
          	{
          		JOptionPane.showMessageDialog
				  (null, "You must make an entry in the InputBox");
          		System.exit (0);
          	}
          	else
          	if (Integer.parseInt(response) < 1 | Integer.parseInt(response) > 3)
          	{
          		JOptionPane.showMessageDialog
				    (null, response + " - is not a valid student type");
          		System.exit (0);
          	}
 public class BankTransaction {
          public static void makeDeposit() {
          }
 }
           
          	if (Integer.parseInt (response) == 1){
          		BankTransaction transaction = new BankTransaction();
          		transaction.makeDeposit();
          	}
          public static void makeWithdrawal() {
            if (Integer.parseInt (response) == 2){
          		BankTransaction transaction = new BankTransaction();
          		transaction.makeWithdrawal();
          		
          		}
          	}
          public static void getBalance() {
          	 if (Integer.parseInt (response) == 3){
          		BankTransaction transaction = new BankTransaction();
          		transaction.getBalance();
          	}
          	moreBankingBusiness = JOptionPane.showInputDialog
			   ( "Do you have more banking business?" ){
          	moreBankingBusiness= moreBankingBusiness.toUpperCase();
          	}  
          	
          	JOptionPane.showMessageDialog
			  (null, "Thanks for banking with us!");
          } 
}

After I ran that i got this here,

Code:
Syntax error, insert "}" to complete Block
	Syntax error, insert "else Statement" to complete IfStatement
	Syntax error, insert "}" to complete Statement

	at classpractice7_1.main(classpractice7_1.java:55)
Exception in thread "main"
 
Associate
Joined
24 Jun 2008
Posts
1,168
Oh come on, even I can work out what that means!
You have got your } in the wrong place and one too many.


Code:
public static void makeDeposit() {
  [COLOR="Red"][B]        }
 }[/B][/COLOR]
           
          	if (Integer.parseInt (response) == 1){
          		BankTransaction transaction = new BankTransaction();
          		transaction.makeDeposit();
          	}
 
Last edited:
Associate
Joined
24 Jun 2008
Posts
1,168
Also, am I helping you with your home work or something as I think you need to go back to basics.
the bits you have
Code:
import javax.swing.JOptionPane;
public class classpracyice6_2 {
static double balance = 0;
static double newBalance = 0;
static double adjustment = 0;

public static void main(String[] args) {
	String response;
	String moreBanKingBusiness;
	moreBanKingBusiness = JOptionPane.showInputDialog("DO you want to do some banking?");
	moreBanKingBusiness = moreBanKingBusiness.toUpperCase();
	while (moreBanKingBusiness.equals ("YES")){
		response = JOptionPane.showInputDialog("What would you like to do?, (1=Deposit, 2=Withdraw, 3=Get Balance)");
		if (response == null)
		{
			JOptionPane.showMessageDialog(null, "You clicked on the Cancel button");
			System.exit (0);
		}
		else If (response.equals(""))
		{
			JOptionPane.showMessageDialog(null, "You must make an entry in the InputBox");
			System.exit (0);
		}
		else if (Integer.parseInt(response) < 1 | Integer.parseInt(response) > 3)
		{
			JOptionPane.showMessageDialog(null, response + " - is not a valid banking function");
			System.exit (0);
		}
		if (Integer.parseInt(response) == 1) {
			BankTransaction transaction = new BankTransaction();
                        transaction.makeDeposit();
		}
		if (Integer.parseInt(response) == 2) {
			BankTransaction transaction = new BankTransaction();
                        transaction.makeWithdrawal();
		}
		if (Integer.parseInt(response) == 3) {
			BankTransaction transaction = new BankTransaction();
                        transaction.getBalance();
		}

		moreBanKingBusiness = JOptionPane.showInputDialog("Do you have more banking buiness?");
		moreBanKingBusiness = moreBanKingBusiness.toUpperCase();
		
	} //end of while loop
	
	JOptionPane.showMessageDialog(null, "Thanks for banking with us!");
	System.exit (0);
} // end of main

public class BankTransaction {
	public static void makeDeposit() {
		adjustment = Double.parseDouble(JOptionPane.showInputDialog( "Enter the Deposit Amount" ));
		newBalance = balance + adjustment;
		JOptionPane.showMessageDialog(null, "*** My National Bank ***\n\n" + "Old Balance is: " + balance + "\n" + "Adjustment is: +" + adjustment + "\n" +	"New Balance is: " + newBalance + "\n");
		balance = newBalance;
	}
	public static void makeWithdrawal() {
		adjustment = Double.parseDouble(JOptionPane.showInputDialog( "Enter the Withdrawal Amount" ));
		newBalance = balance - adjustment;
		JOptionPane.showMessageDialog(null, "*** My National Bank ***\n\n" + "Old Balance is: " + balance + "\n" + "Adjustment is: -" + adjustment + "\n" +	"New Balance is: " + newBalance + "\n");
		balance = newBalance;
	}
	public static void getBalance() {
		JOptionPane.showInputDialog	(null, "*** My National Bank ***\n\n" + "Your Current Balance is: " + balance );
	}
}
}// ends class classpracyice6_2
 
Last edited:
Back
Top Bottom