Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Help! Trying to create a tracker for the team - Limit User viewership

User_7A04POct 20 2020

Hey Team,
I was trying to create an application to track certain details but the data is viewable to everyone . I want to limit data view to only that individual and the entire data to the Administrator only.
Please help me out!
I have no experience in coding etc :)
Thanks,
Benson

Comments

NickR2600-Oracle

Hi Carol,

    I don't mind the questions, not at all.  One of the benefits of the game is that it spurs people have conversations about Java.  I'm glad you're poking around the code and being curious.  And if any lesson were to give people trouble, it would be the final lesson.

1) You could initialize the transactions field to 0 from the Account constructor.  However, it's not necessary.  If a number field (like an int or double) isn't explicitly given an initial value, its value becomes 0.  In other words, it defaults to 0.  Correct, transactions would be an instance variable.

2) NewFXMain is where the ArrayList is first created and where account instances are added to that list.  But while that's going on, the ButtonController class has no idea that particular ArrayList even exists!  All it knows is that it'll have to work with some sort of ArrayList.  A buttonController instance wouldn't be able to work with an ArrayList unless we explicitly tell it which ArrayList instance we're talking about.  This line of code from NewFXMain creates a ButtonController instance named buttonController and tells it which ArrayList to use:

ButtonController buttonController = new ButtonController(accountList, ownerSearchBar, numberSearchBar, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8);

The ButtonController class saves this ArrayList as a field.  The variable used to save this information is coincidentally is also called accountList.  We could name the variable whatever we want, and it will still point to the same ArrayList created in NewFXMain.

Nick

3462211

Thanks a lot for your explanation Nick.  For question 1), I should have copy-typed your code (please see below) or worded my question a bit better.  I think I meant to ask:  Is there any particular reason you choose to initialize the instant variable transactions in the field declaration area instead of constructor?

public abstract class Account {

    //Fields

    protected String accountOwner;

    protected double balance;

    protected int accountNum;

    protected int transactions = 0;

    protected static int nextAccountNum = 0;

   

   

    //Constructor

    public Account(String o, double b){

        accountOwner = o;

        balance = b;

        setAccountNumber();

        System.out.println("New Account:");

        printDetails();

    }

Carol

NickR2600-Oracle

Hmm... I may have been thinking "For every field which doesn't require a value to be passed to the constructor, I'll set its initial value where the field is declared." 

Nick

1 - 3

Post Details

Added on Oct 20 2020
11 comments
207 views