Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: What am I missing here?

  1. #1
    Junior Member
    Join Date
    Jan 2022
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default What am I missing here?

    Hello,

    I'm trying to figure out what I'm doing wrong here. For an assignment I need to get people with a VIP pass in the correct row when entering a Bakery.

    Row 1 is for people with a VIP pass. However, that row can only take 10 people in line (after they remodel, it can take 15. But I'm not that for in the assignment yet). So if there are 10 people in row 1, the 11th should go to row 2.

    In the code below, I get the people in the right row. However, if I want to add an 11th person with VIP pass, it should go to row 2, but with this piece of code it will go to row 1. I've been trying to change things, but that doesn't work.

    What am I missing/doing wrong here?

    Thanks for the help!

    public class Bakery
    {
        // instance variables
        private String name;
        private int MaxInRow1;
        private ArrayList<Person> row1; //people with VIP pass
        private ArrayList<Person> row2; //people without VIP pass
     
        /**
         * Constructor for objects of class Bakery
         */
        public Bakery (String name)
        {
            this.name = name;
            MaxInRow1 = 10;
            row1 = new ArrayList<Person> ();
            row2 = new ArrayList<Person> ();
        }
     
        public void enterBakery (Person name) //
        {
            if (name.hasVIPpass() == true)
            {
                int MaxInRow1 = 0;
     
                if (MaxInRow1 < 10)
                {
                    row1.add(name);
                }
                else
                {
                    row2.add(name);
                }
     
            }
     
            else 
            {
                row2.add(name);
            }
        }
    Last edited by F_VRBRG; May 2nd, 2022 at 05:50 AM.

  2. #2
    Member
    Join Date
    Apr 2022
    Posts
    36
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: What am I missing here?

    you need to increment variable MaxInRow1
    int MaxInRow1 = 0;
    if (name.hasVIPpass() == true) {
     
                if (MaxInRow1 < 10)
                {
                    row1.add(name);
                    MaxInRow1++;
                }
                else
                {
                    row2.add(name);
                }
     }

  3. #3
    Junior Member
    Join Date
    Jan 2022
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default SOLVED: What am I missing here?

    Thanks for the reply, it works!
    Last edited by F_VRBRG; May 2nd, 2022 at 05:50 AM.

Similar Threads

  1. [SOLVED] What am I missing???
    By Sailorgary1964 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 21st, 2014, 06:50 AM
  2. [SOLVED] 'ELSE' missing 'IF'
    By Andrew Red in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 30th, 2013, 11:51 AM
  3. What am I missing?
    By jean28 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 28th, 2012, 10:49 AM
  4. What am I missing?
    By prgmrGrl in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 10th, 2012, 12:33 AM
  5. Missing drivers?
    By mjpam in forum JDBC & Databases
    Replies: 5
    Last Post: September 6th, 2010, 08:00 PM