| | |
Array Selections
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2007
Posts: 58
Reputation:
Solved Threads: 0
Hello everyone. I'm currently having a problem with choosing one area in an array. For what I'm working on I'm trying to pick one seat in an array consisting of 10 seats. The first 5 seats are firstclass and the last 5 seats are economy. For example if the person picks firstclass they should be issued one seat out of the five but my program keeps selecting 5 seats. Here is an example of what I'm doing.
java Syntax (Toggle Plain Text)
import java.util.Scanner; public class Flight { public static void main(String[] args) { Scanner input = new Scanner(System.in); int sectionnumber; String selectionletter; int seats[] = new int[9]; System.out.println ("*************** Airline Reservation System ****************"); System.out.println ("Please type 1 for First Class or 2 for Economy"); sectionnumber = input.nextInt(); // Lets user select first class or economy if (sectionnumber == 1) { for (int firstclass = 1; firstclass < 6; firstclass++) { System.out.println("Your seat number is: " + firstclass); } } if (sectionnumber ==2) { for (int economy = 6; economy < 11; economy++) { System.out.println("Your seat number is: " + economy); } }
•
•
Join Date: May 2008
Posts: 38
Reputation:
Solved Threads: 2
hi,
i think you should construct your program differently , the reason behind is the for loops. When the user enters 1, for the first class , it will go to
Where you are issuing all the five tickets associated to first class.
i think you should construct your program differently , the reason behind is the for loops. When the user enters 1, for the first class , it will go to
Java Syntax (Toggle Plain Text)
for (int firstclass = 1; firstclass < 6; firstclass++) { System.out.println("Your seat number is: " + firstclass); }
•
•
Join Date: Aug 2007
Posts: 58
Reputation:
Solved Threads: 0
How can I go about doing so. Arrays are my weakest areas. I have the Java How to Program Seventh addition book which goes into details about arrays but doesn't have an example where it actually asks the user to input information and then access the array to match it up. All it has are examples of data already created to put into an array. Thanks in advance.
•
•
Join Date: May 2008
Posts: 38
Reputation:
Solved Threads: 2
It can be done without using arrays but if you have to use it then , do you have to actually store the name of the person in an array element.
For example
Adam = seat[0];
like this ?
Anyway i have done a code without array check it , if it might give some help
For example
Adam = seat[0];
like this ?
Anyway i have done a code without array check it , if it might give some help
Java Syntax (Toggle Plain Text)
import java.util.*; class Flight { Scanner in = new Scanner(System.in); void issue () { int sectionnumber; int count=1; int count1=1; System.out.print("\n**********AirLine Program***********\n"); for(int i = 0 ;i<=9;i++) { System.out.print("\nPlease type 1 for First Class and 2 for Second class"); sectionnumber = in.nextInt(); if (sectionnumber==1) { if(count >=6) { System.out.print("\nNo more seats available in first class"); } else { System.out.print("\nYour seat number is:"+count); count++; } } else if (sectionnumber ==2) { if(count1 >=6) { System.out.print("\nNo more seats available in Second class"); } else { System.out.print("\nYour seat number is:"+count1); count1++; } } } } }
Last edited by Software guy; Jul 15th, 2008 at 5:06 pm. Reason: Some thing different in code
![]() |
Similar Threads
- Programming VBA: Reading excel into an Array (Visual Basic 4 / 5 / 6)
- turn this array into a form (PHP)
- Store multiple selection from pagination info into single array (PHP)
- problems with array! (Pascal and Delphi)
- An array of arrays of of radio buttons (JavaScript / DHTML / AJAX)
- How can I use the Checkboxes into a Tree Control (C++)
- HTML Select and PHP 5 - Issue (PHP)
- How many different numbers are there? (C++)
- Urgent help needed !!! (PHP)
Other Threads in the Java Forum
- Previous Thread: Conference Centre
- Next Thread: Need help in stroke and shape
| Thread Tools | Search this Thread |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class classes click client code compare component coordinates database detection doctype eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool linux list loop map method methods mobile netbeans newbie nextline object pong print problem program programming project recursion recursive rim scanner screen sell server set size sms sort sql string swing terminal threads tree user web websites windows





