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!");
}
}
 
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.
 
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();
}
 
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 );
}
}//
 
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"
 
Oh come on, even I can work out what that means!
You have got your } in the wrong place and one too many.
Your right, it was done in haste, sorry

Youll be pleased to know it is not any homework. It is something I'am playing around with.
 
Back
Top Bottom