|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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;
}
}
}
}
Last edited by The Midnighter; 11-06-2007 at 12:57 PM. |
| Sponsored Links |
|
|
|
|||
|
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.");
}
}
}
}
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. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |
Goal: 100,000 Posts
Complete: 79%