Share on Google+Share on Google+

leowlinfang
OOP with Java-Array
1 Answer(s)      8 years ago
Posted in : Java Beginners

Ads

View Answers

March 20, 2009 at 11:44 PM


Hi Friend,

Here is the code for solving your problem. Please try the following code:

import java.io.*;

public class AirlineReservation {

public static void main(String args[]) throws Exception {

String[][] seats = new String[7][4];

for (int i = 0; i < 7; i++) {
seats[i][0] = "A";
seats[i][1] = "B";
seats[i][2] = "C";
seats[i][3] = "D";
}

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

while (true) {
System.out.println("1. Display");
System.out.println("2. Assign");
System.out.println("3. Exit");
System.out.println("Enter your choice : ");

String choice = br.readLine();

switch (Integer.parseInt(choice)) {
case 1:
display(seats);
break;

case 2:
assign(seats);
break;

case 3:
exit();
break;

default:
System.out.println("Invalid input");
}
}
}

public static void display(String seats[][]) {
for (int i = 0; i < 7; i++) {
System.out.print(i + 1);
for (int j = 0; j < 4; j++) {
System.out.print(" " + seats[i][j]);
}
System.out.println();
}
}

public static void assign(String seats[][]) throws Exception {

display(seats);

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter row = ");
String row = br.readLine();
System.out.println("Enter seat (A, B, C, D) = ");
String col = br.readLine();

for (int i = 0; i < 4; i++) {

if (seats[Integer.parseInt(row) - 1][i].equalsIgnoreCase(col)) {
seats[Integer.parseInt(row) - 1][i] = "X";
}
}
}

public static void exit() {
System.exit(0);
}
}

Thanks
RoseIndia Team









Related Tutorials/Questions & Answers:
OOP with Java-Array - Java Beginners
OOP with Java-Array  Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numberings as follows: 1 A B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7
oop concept
oop concept  why Object class is super class for all class? 1.to use the Object class methods in subclass directly or 2.the Object class is usefull at the time of object create of subclass what
Advertisements
OOP
oop
oop  can you tell me about why java is not 100% object oriented language
OOP - Java Beginners
OOP Design Pattern  What is the oops design patterns
php oop functions
php oop functions  Just a quick question... php oop functions. can i call the main class function from an instantiated object of the child class
Java with OOP assignment (Eclipse)
Java with OOP assignment (Eclipse)  How do i control the length of characters in an input? E.g.: Enter your name > Hi * Name too short
Java array
Java array   How can one prove that the array is not null but empty
PHP OOP Concepts
PHP OOP Concepts Object Oriented Programming  is a paradigm which is nowadays the most popular way to develop any application and most of the modern day language is based on this paradigm. OOP or Object Oriented Programming PHP has
oop answers - Java Beginners
oop answers  Consider the following declarations: { private int.... Write a Java statement that prints the values of the instance variables of x. i. Write a Java statement that creates the XClass object t and initializes
OOP JAVa - Java Interview Questions
OOP JAVa  Is java is 100% OOP.?Plz giv full explanation.  hi Sanjay,dis is Srinivas(MCA from Andhra University).....Java is not an 100 % OOPL,because of the availability of Primitive Data Types
OOP questions - Java Beginners
OOP questions  Consider the following declarations: { private... of a and the instance variable w is initialized to the value of b. h. Write a Java statement that prints the values of the instance variables of x. i. Write a Java
what is the difference between pop and oop
what is the difference between pop and oop  what is the difference between pop and oop
java array
java array Two cells is a matrix will be called connected if they are adjacent...], a[3,2], a[3,3] } elements with weight 6 Problem: Implement Java code which takes 2 dimensional integer array as input and prints out heaviest island
OOP - Java Beginners
OOP  i have problem with OOP hope u'll help me write a program that allows the user to enter student' names followed by their test scores and outputs...://www.roseindia.net/java/master-java/java-object-oriented-language.shtml
OOP questions - Java Beginners
OOP questions  Consider the following declarations: { private int u; private double w; public XClass() { } public XClass(int a, double...; } For more information on Java visit to : http://www.roseindia.net/java
OOP with Java - Java Beginners
OOP with Java  I had a look at the solution for the answers, in the website already, but my lecturer wants us to do it in another method. Here goes...) { Question2 q = new Question2(); q.buildSeats(); q.printSeats
OOP using Java - Java Beginners
OOP using Java  Can you write a Java statement that creates the object mysteryClock of the Clock type, and initialize the instance variables hr,min...); } } For more information on Java visit to : http://www.roseindia.net/java
OOP with Java 2 - Java Beginners
OOP with Java 2  Define a class called BogEntry that could be used to store an entry for a Web log. The class should have member variables to store the poster's username, text of entry, and the date of the entry using the Date
OOP Using JAVA - Java Beginners
OOP Using JAVA  OBJECT ORIENTED PROGRAMMING USING JAVA (hope guys u will help me please i need your help,thank you so much) Create a Java program...(); oops.OopType(); } } For more information on Java visit to : http
Java Array Types
Java Array Types  Hi, Can Some one guide me how many types of Java Array uses in developing an application. I need the online tutorial to learn syntax or code of the various types of Java arrays. Thanks
OOP with Java 3 - Java Beginners
OOP with Java 3  Write a Temperature class that has two instances variables: temperature value (a floating-point number) and a character for the scale, wither C for Celsius or F for Fahrenheit. the class should have four
registration form using oop concept
registration form using oop concept  I would like to write a program student registration form at kindergartens and display the information of students that register to the kindergarten. How to make the form and display
java array problem
java array problem  suppose i have an array a[] at a[0] i have value 5,7 the thing is that i want to assign the value of array a[0]=5,7 to two variable let it be j,k that is j=5 and k=7 plz help regards
java oop
java oop  Design and implement a class called DayType that implements the day of the week in a program. The class DayType should store the day, such as Sun for Sunday, Mon for Monday and so on and so forth. The program should
Java array in currency converter
Java array in currency converter  Hi all, My sister is trying to teach me java. She's in school for programming and I'm not but I am just trying to learn alongside her. I am quite lost with this multidimensional array. I do
java array sorting manual way
java array sorting manual way  Hi, Anyone has any sample code on how to sort a array manually without using the inbuild sorting algorithm? Thanks
PHP OOP Namespace
Namespace in PHP: The term namespace is very much common in OOP based language, basically it is a collection of classes, objects and functions. Namespaces... should always declare on the top of the page. PHP OOP Namespace Example: <
Java with OOP assignment (Eclipse) - Java Beginners
Java with OOP assignment (Eclipse)  "THREE Ts GAME" *Description* A "tic-tac-toe" game is a two player's board game where the game board..." games using Java. When your game application started, the players will be able
java array question. - Java Beginners
java array question.  I need help with this: Create a program that will generate 50 random numbers between the range of -5 and 45 and store them in an array. Have the program then print the numbers in rows of 10 and calculate
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads