kamenica's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
8 (0.02 per day)
Joined:
20-March 12
Profile Views:
54
Last Active:
User is offline Apr 18 2012 01:55 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   kamenica has not set their status

Posts I've Made

  1. In Topic: Arraylist and for loops

    Posted 6 Apr 2012

    Yhank you very much for your help :) Before I saw your answer, I did this:

      public int getPages() {
            int sum = 0;
            for (Chapter chapter : chapters) {
                sum = chapter.getPages() + sum;
            }
            return sum;
    
    


    Could it be done that way also? I just need it to tell me how many pages a certain chapter is in the book.



    View Postkarabasf, on 06 April 2012 - 04:08 AM, said:

    So you need to get the amount of pages of the book right?

    Well, you certainly need a for-loop and it does not really matter what kind of for loop you'd use. As you're storing Chapter objects in your arraylist, you could simply loop with a foreach loop and retrieve the amount of pages. In pseudocode it would look like something like this:

    getpages()
    int pagecount = 0;  //You start with 0 pages before you loop
    for each Chapter c in chapters
       pagecount += c.getpage() //Add the pagecount of each chapter to the total page count
    
    return pagecount;
    
    


    On the other hand, if you don't want to use a foreach loop, you need to know the size of the arraylist (at least, you need to know the amount of chapters it's holding) In pseudocode, this would look like this:

    getpages()
    int totalChapter = chapters.size() //get the total amount of chapters it's holding
    
    int pagecount = 0;
    for(int i = 0; i < totalChapter; i++){
      Chapter temp = chapters.get(i);  //Get the chapter object at position i
      pagecount += temp.getpage() //Add the amount of pages of each chapter to the pagecount
    }
    
    return pagecount;
    
    


    Good luck! ^^

    Edit: Someone opened a double topic...
  2. In Topic: Help needed for a cinema booking system.

    Posted 20 Mar 2012

    View PostGregBrannon, on 20 March 2012 - 10:27 AM, said:

    I may interpret the question incorrectly, but I think it means:
    public int getSeats()
    {
       return seats;
    }
    

    and the same for getRows().

    Let me know if you think my interpretion or the translation is wrong.

    Edit: I meant to address your comment about returning an array, even though I don't read the assignment as asking you to return one, but I could be wrong.

    The method has to be defined as returning an array:

    public int[][] getArray()

    and then the return statement will include just the name of the array:

    public int[][] getArray()
    {
       // declare and define the size of the array
       int[][] myArray = new int[5][5];
    
       // fill the array with good data
    
       // return the array
       return myArray;
    }
    


    Thank you very much for your time and help. I appreciate it :-) I'll try to work on it, and see what I can do, else I am going to post again. :-)
  3. In Topic: Help needed for a cinema booking system.

    Posted 20 Mar 2012

    View PostGregBrannon, on 20 March 2012 - 07:57 AM, said:

    Here's the Oracle tutorial for JTextArea, but where's your code that builds the GUI?

    As for your getSeats() and getRows() methods, the assignment asks:

    Quote

    5. Create a method getRows and getSeat(s?) that returns rows and seats in the cinema.

    I would think you'd simply return the 'rows' and 'seats' variables created in Step 2, so I'd make them instance variables.


    Thanks for you reply Greg. So for getRows and getSeats, I can just write as follows:

    public int[] getRows(int row){
    return ticket[row];

    and the same for getSeats?

    I've never tried to return an array before, therefore the question.

    The code for getShow for the jTextField is not ready yet, right now I'm trying to write the code that can return those followin things in step 6. That is bothering me :-)
  4. In Topic: Help needed for a cinema booking system.

    Posted 20 Mar 2012

    View PostGregBrannon, on 20 March 2012 - 07:18 AM, said:

    I might be off, but I believe Step 6 returns theater information by show and time that includes an array (?) that summarizes the seat status "where seats is shown with "." if they contain 0, "#" if they contain customer and "X" otherwise.

    So if you have an array seatStatus( row, seat ), the array will contain

    seatStatus( row, seat ) = "." if the seat is empty,
    seatStatus( row, seat ) = "#" if the seat is booked, or
    seatStatus( row, seat ) = "X" if the seat is neither booked nor empty.

    I'm not sure what the last category, "X", is for. Broken, reserved, unavailable? Who knows.

    Does that help?



    GregBannon
    You're right, step 6 should return seatStatus like this for instance:

    1: . . . . . . . . . . . .
    2: . . . . . . . . . . . .
    3: . . . . . . X X . . .
    4: . . . . . . . . . . . .
    5: . . . . . . . . . . . .
    6: . . X X . # # X X
    7: . . . X X X X X .
    8: . . . . . . . . . . . .
    9: . . . . . . . . . . . .
    10: . . . . X X X . . .

    The X is if they f.ex contain a reserved seat or so.

    But how do I implement this so it will show up like that on a jTextArea f.ex?
    And are my getSeat and getRow method right? They should each return seats and rows, for instance if it's [20][10] it should return 20 rows, and 10 seats.

    Thanks for the help.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

kamenica hasn't added any friends yet.

Comments

kamenica has no profile comments yet. Why not say hello?