• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help!!

 
whu ando
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've just started studying Java at uni and am struggling to set up java properly at home. I've compiled and run this program at uni but when i do it at home, i get this error message:
---------- Compiler ----------
CreditCardApplication.java:55: cannot find symbol
symbol : class CreditCard
location: class CreditCardApplication
public static CreditCard enterData()
^
CreditCardApplication.java:20: cannot find symbol
symbol : class CreditCard
location: class CreditCardApplication
CreditCard card1, card2;
^
CreditCardApplication.java:57: cannot find symbol
symbol : class CreditCard
location: class CreditCardApplication
CreditCard card = null;
^
CreditCardApplication.java:86: cannot find symbol
symbol : class CreditCard
location: class CreditCardApplication
card = new CreditCard(Long.parseLong(creditCardNumberStr), Integer.parseInt(customerNumberStr));
^
CreditCardApplication.java:90: cannot find symbol
symbol : class CreditCard
location: class CreditCardApplication
card = new CreditCard(Long.parseLong(creditCardNumberStr), Integer.parseInt(customerNumberStr),
^
CreditCardApplication.java:95: cannot find symbol
symbol : class CreditCard
location: class CreditCardApplication
card = new CreditCard(Long.parseLong(creditCardNumberStr), Integer.parseInt(customerNumberStr),
^
6 errors

Output completed (3 sec consumed) - Normal Termination

I can't work out what's different between my setup and the setup at uni.
Any ideas??
 
Roy Simon
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that this class :CreditCard is in your classpath and then try compiling your program.
Another reasson maybe that u have not imported that class.
if this class is in another location then use the -classpath option in the java compiler, point it to the folder containing the abv class and then compile

If this class is in another package use the import command and here also the package path should be in the classpath.

Regards
Simon
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to put upon the code.. only then we can help you better.. and wat simon given is a very valid point. check out the classpath.
 
whu ando
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate to dump code on the site but this is the code to the previous error message:

import javax.swing.*;

class CreditCardApplication
{
public static void main (String[] args)
{
CreditCard card1, card2;
// enter data is 2a, note that we don't have to create card1 or card2 (using 'new') because it's done by enterData
card1 = enterData();
card2 = enterData();

// this could be 2d
//note that the .equals is a method in CreditCard class, works on card number, could work on cust number
if (card1.equals(card2))
JOptionPane.showMessageDialog(null, "Sorry card 2 is invalid, customer can only have 1 card");
/*
if (card1.getCustomerNumber() == card2.getCustomerNumber())
{
JOptionPane.showMessageDialog(null, "Sorry card 2 is invalid as a customer can only have 1 card");
card2 = null;
}
*/

// use the card, do what you like here to show that it all works
System.out.println("Fee $" + card1.calculateFees());
// card1.buySomething(200); // e.g. from $100 to -$100, should increase the fees
System.out.println("Balance $" + card1.getAccountBalance());
System.out.println(card1.buySomething(200));
System.out.println("Balance $" + card1.getAccountBalance());
System.out.println("Fee $" + card1.calculateFees()); // fee is 4.60 + 1/12 of 10% of balance is ~$5.40
// card1.buySomething(10000);
System.out.println(card1.buySomething(10000));
// if you try to go over your limit then transaction is rejected, could have a message
System.out.println("Balance $" + card1.getAccountBalance());
// could use 2 methods together to charge fees: card1.buySomething(card1.calculateFees())
card1.buySomething(card1.calculateFees());
System.out.println("Balance $" + card1.getAccountBalance());
System.exit(0);
}

// a method that returns an object, makes creating lots of cards easier
public static CreditCard enterData()
{
CreditCard card = null;
String creditCardNumberStr,
customerNumberStr,
expiryMonthStr,
expiryYearStr,
maximumCreditLimitStr,
accountBalanceStr;

// allow data entry for all the fields for card 1. Any field can be left blank and this should handle it!
creditCardNumberStr = JOptionPane.showInputDialog(null, "Enter Credit Card Number","1234567890123456");
customerNumberStr = JOptionPane.showInputDialog(null, "Enter Customer Number","1");
expiryMonthStr = JOptionPane.showInputDialog(null, "Enter Expiry Month","12");
expiryYearStr = JOptionPane.showInputDialog(null, "Enter Expiry Year","2010");
maximumCreditLimitStr = JOptionPane.showInputDialog(null, "Enter Maximum Credit Limit", "-10000");
accountBalanceStr = JOptionPane.showInputDialog(null, "Enter Account Balance","100");


// test for valid data, note that this is very basic validation, there are still many cases to deal with
// e.g. we're assuming numbers are entered
// note also that not all data is required, there are several constructors that deal with this
if ((creditCardNumberStr.length() == 0) || (customerNumberStr.length() == 0))
{
JOptionPane.showMessageDialog(null, "Insufficient data");
System.exit(1);
}
else
if ((expiryMonthStr.length() == 0) || (expiryYearStr.length() == 0) ||
(maximumCreditLimitStr.length() == 0))
// generate card 1 with constructor A
card = new CreditCard(Long.parseLong(creditCardNumberStr), Integer.parseInt(customerNumberStr));
else
if (accountBalanceStr.length() == 0)
// generate card 1 with constructor B
card = new CreditCard(Long.parseLong(creditCardNumberStr), Integer.parseInt(customerNumberStr),
Byte.parseByte(expiryMonthStr), Short.parseShort(expiryYearStr),
Float.parseFloat(maximumCreditLimitStr));
else
// generate card 1 with constructor C
card = new CreditCard(Long.parseLong(creditCardNumberStr), Integer.parseInt(customerNumberStr),
Byte.parseByte(expiryMonthStr), Short.parseShort(expiryYearStr),
Float.parseFloat(maximumCreditLimitStr), Float.parseFloat(accountBalanceStr));
JOptionPane.showMessageDialog(null, "account balance is " + card.getAccountBalance());
return card;
}
}

Any ideas???
 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate to dump code on the site but this is the code to the previous error message:


As other posters have already mentioned, the problem is that the compiler can't find the CreditCard class. Either the class doesn't exist, or it is not in the compiler's class path.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic