Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Java Help

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-06-2007, 12:39 PM
The Midnighter The Midnighter is offline
Newbie
 
Join Date: Oct 2007
Posts: 14
Credits: 0
Rep Power: 0
The Midnighter is on a distinguished road
Default 2D Array newb

Alright, so basically here's what's supposed to happen.
It's an Airline reservation system, basically taking a row of 10 seats, 1 isle, 1 window. Yes, there's only one row. xD So 5 seats isle, 5 seats window.. Here's the code I have so far:

Code:
package airlineconsole;

import java.io.*;

public class Main
{
    private static BufferedReader stdin = new BufferedReader(
            new InputStreamReader( System.in ) );
    
    /** Creates a new instance of Main */
    public Main()
    {
    }
   
    public static void main(String[] args) throws IOException
    {
        // Init
        boolean[][] array = new boolean[5][5];
        // end Init
        
        System.out.println("Welcome! Please enter the style seating(1 for Economy, 2 for First Class): ");
        String seatStyle = stdin.readLine();
        int seatStyleNum = Integer.parseInt( seatStyle );
        
        for (int i=0;i<5;i++)
            for (int j=0;j<2;j++)
            {
                while ((array[i][j]) == false)
                {
                    System.out.println("Seat " +array[i][j]+ " Reserved.");
                    array[i][j] = true;
                }
            }
    }
}
My problem is, this goes through the entire array, and prints out EVERY seat. But I don't understand why it's doing that, since I set the value to TRUE after the fact?

Last edited by The Midnighter; 11-06-2007 at 12:57 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-06-2007, 02:03 PM
The Midnighter The Midnighter is offline
Newbie
 
Join Date: Oct 2007
Posts: 14
Credits: 0
Rep Power: 0
The Midnighter is on a distinguished road
Default

Alright, I'm not going to edit my old post because I want people to be able to see the complete code for that, but I'm not going to make a new thread because it's the same program as this one.. Anyway,

Updated code:
Code:
/*
 * Main.java
 *
 * Created on November 6, 2007, 12:56 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package airlineconsole;

import java.io.*;

/**
 *
 * @author Administrator
 */
public class Main
{
    private static BufferedReader stdin = new BufferedReader(
            new InputStreamReader( System.in ) );
    
    /** Creates a new instance of Main */
    public Main()
    {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException
    {
        while(true)
        {
            // Init
            int[][] array = new int[5][2];
            boolean finished = false;
            // end Init
            
            //System.out.println("Welcome! Please enter the style seating(1 for Economy, 2 for First Class): ");
            System.out.println("1: Window seat\n2: Isle seat: ");
            String seatStyle = stdin.readLine();
            int seatStyleNum = Integer.parseInt( seatStyle );
            
            if(seatStyleNum == 1)
            {
                for (int j=0;j<5;j++) // J Is the Window Seat
                {
                    if (array[0][j]==0)
                    {
                        System.out.println("Window seat " +array[0][j]+ " reserved.");
                        array[0][j] = 1;
                        finished = true;
                        break;
                    }
                    if (finished == true) break;
                }
            }
            else if (seatStyleNum == 2)
            {
                for (int i = 0; i<5; i++) // I is the Isle seat
                {
                    if (array[i][0] == 0)
                    {
                        System.out.println("Isle seat " +array[i][0]+ " reserved.");
                        array[i][0] = 1;
                        finished = true;
                        break;
                    }
                    if (finished == true) break;
                }
            }
            else
            {
                System.out.println("1 / 2 are the only valid options.");
            }
        }
    }
}
Now, here's my NEW problem:

It's like, it's not filling the array with "1", because it keeps printing "Window seat 0 reserved"... Doesn't array[i][0] = 1; put 1 there?

Last edited by The Midnighter; 11-06-2007 at 05:14 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-06-2007, 05:52 PM
The Midnighter The Midnighter is offline
Newbie
 
Join Date: Oct 2007
Posts: 14
Credits: 0
Rep Power: 0
The Midnighter is on a distinguished road
Default

A buddy of mine fixed the problem, had the initlization wrong >.< Was creating the array inside the loop geeez..........
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-06-2007, 09:56 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 3,205
Last Blog:
Passwords
Credits: 842
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default

Glad you could get it fixed.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help regarding the sorting of arrays with flags! Yuriy M C and C++ 3 10-12-2007 10:30 PM
Usage of array structures to increment letter instances of text Yuriy M C and C++ 2 09-13-2007 10:49 AM
fread into array position kenna C and C++ 0 08-17-2007 08:03 AM
Python 2D array question annannienann Python 3 04-23-2007 04:36 PM
Is string in array? smith Perl 2 02-14-2007 01:30 PM


All times are GMT -5. The time now is 04:31 AM.

Contest Stats

Xav ........ 1024.41
MeTh0Dz|Reb0rn ........ 974.08
morefood2001 ........ 850.04
John ........ 841.93
WingedPanther ........ 661.52
marwex89 ........ 575.59
Brandon W ........ 456.18
chili5 ........ 292.12
orjan ........ 187.41
Steve.L ........ 181.88

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 79%

Ads