0

I'm supposed to make two java programs that are related, Account.java

public class Account {
// Declarations
String Number = "null";
String Type = "null";
String Card = "null";
String Date = "null";

protected Account() {

}

public String toString() {
    return "\n\t Your account number is " + Number + ",your account type is " + Type + ",your card number is " + Card
            + ".\n\t your expireation date is: " + Date;
}

protected String getNumber() {
    return Number;
}

protected void setNumber(String number) {
    this.Number = number;
}

protected String getType() {
    return Type;
}

protected void setType(String type) {
    this.Type = type;
}

protected String getCard() {
    return Card;
}

protected void setCard(String card) {
    this.Card = card;
}

protected String getDate() {
    return Date;
}

protected void setDate(String date) {
    this.Date = date;
}  }

and AccountTester.java

import java.util.Scanner;
public class AccountTester {
public static void main(String[] args) {
    // Create Objects
    Scanner s = new Scanner(System.in);
    Account a = new Account();

    // auto with nothing set
    System.out.print("Your account information is curently set to" + a
            + "\n\n");

    // set info for account
    System.out.print("Please, enter your account number: \t");
    a.setNumber(s.nextLine());
    System.out.print("Please, enter your account type: \t");
    a.setType(s.nextLine());
    System.out.print("Please, enter your card number: \t");
    a.setCard(s.nextLine());
    System.out.print("Please, enter your expire date: \t");
    a.setDate(s.nextLine());

    System.out.print(a);

} }

The first code has no problems, but in the 2nd code in the line that says

"Account a = new Account();"

it shows an error saying "cannot find symbol, symbol class Account, location class accountTester". I tried changing it to

"AccountTester a = new Account();"

But it not only did it not fix it, but it also made all the codes with "a.set" give out the same "cannot find symbol" error. How can I fix this

Alex Simmons
  • 11
  • 1
  • 2
  • Your constructor should be `public`, not `protected`. – Jacob G. Feb 20 '18 at 04:34
  • 1
    @JacobG. Doesn't matter if they are in the same package. Since they are probably both in the unnamed package, it doesn't matter. – Andreas Feb 20 '18 at 04:36
  • 1
    Are the two `.java` files in the same directory? How are you compiling them? – Andreas Feb 20 '18 at 04:37
  • *FYI:* Java naming convention is for field names to start with lowercase letter. – Andreas Feb 20 '18 at 04:38
  • @Andreas if it's a `cannot find symbol`, I assume the classes aren't in the same package and OP isn't importing `Account`. – Jacob G. Feb 20 '18 at 04:38
  • 2
    @JacobG. Since OP is showing `import` statement, then OP would likely also have shown `package` statement if it had been there. It's not, so fair *assumption* is that both are in the unnamed package. But I did say "if" and "probably", since I'm guessing. You didn't condition your comment, and it's only correct for some scenarios, which is why I added my comment clarifying that. – Andreas Feb 20 '18 at 04:40

1 Answers1

0

You're creating a model and you want to import your model POJO Account to be used in another java classes in a different package of the package where you created the class. if it so, please change all your protected methods to public methods. That's because when you are importing the class and then construct it. Java cannot create your model because at runtime there is no access. Please change it. here is a link for more information.

link

To work, it has to be in the same package!!

I hope to help you!!

Kenry Sanchez
  • 1,703
  • 2
  • 18
  • 24