OOP with Java-Array

OOP with Java-Array

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  can you tell me about why java is not 100% object oriented language
OOP
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 array
Java array   How can one prove that the array is not null but empty
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
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
ModuleNotFoundError: No module named 'oop-ext'
ModuleNotFoundError: No module named 'oop-ext'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'oop-ext' How to remove the ModuleNotFoundError: No module named 'oop-ext
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
what is the difference between pop and oop
what is the difference between pop and oop  what is the difference between pop and oop
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
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 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
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 - 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 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
ModuleNotFoundError: No module named 'distributions-practice-OOP'
ModuleNotFoundError: No module named 'distributions-practice-OOP'  Hi...: No module named 'distributions-practice-OOP' How to remove the ModuleNotFoundError: No module named 'distributions-practice-OOP' error? Thanks
ModuleNotFoundError: No module named 'distributions-practice-OOP'
ModuleNotFoundError: No module named 'distributions-practice-OOP'  Hi...: No module named 'distributions-practice-OOP' How to remove the ModuleNotFoundError: No module named 'distributions-practice-OOP' error? Thanks
ModuleNotFoundError: No module named 'distributions-practice-OOP'
ModuleNotFoundError: No module named 'distributions-practice-OOP'  Hi...: No module named 'distributions-practice-OOP' How to remove the ModuleNotFoundError: No module named 'distributions-practice-OOP' error? Thanks
ModuleNotFoundError: No module named 'DS-OOP-Review'
ModuleNotFoundError: No module named 'DS-OOP-Review'  Hi, My... 'DS-OOP-Review' How to remove the ModuleNotFoundError: No module named 'DS-OOP-Review' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'bottle-oop-rest'
ModuleNotFoundError: No module named 'bottle-oop-rest'  Hi, My... named 'bottle-oop-rest' How to remove the ModuleNotFoundError: No module named 'bottle-oop-rest' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'distributions-practice-OOP'
ModuleNotFoundError: No module named 'distributions-practice-OOP'  Hi...: No module named 'distributions-practice-OOP' How to remove the ModuleNotFoundError: No module named 'distributions-practice-OOP' error? Thanks
ModuleNotFoundError: No module named 'DS-OOP-Review'
ModuleNotFoundError: No module named 'DS-OOP-Review'  Hi, My... 'DS-OOP-Review' How to remove the ModuleNotFoundError: No module named 'DS-OOP-Review' error? Thanks   Hi, In your python
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  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
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 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
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 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 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
Helpin OOP
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
it.unibo.tuprolog - oop-lib-jvm version 0.31.10 Maven dependency. How to use oop-lib-jvm version 0.31.10 in pom.xml?
this version ( it.unibo.tuprolog - oop-lib-jvm version 0.31.10 ) in their Java project...; it.unibo.tuprolog - oop-lib-jvm version 0.31.10 in Java projects. Follow... and includes  it.unibo.tuprolog - oop-lib-jvm version 0.31.10 java library in your
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.... The namespace should always declare on the top of the page. PHP OOP Namespace
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
it.unibo.tuprolog - oop-lib-jvm version 0.31.5-dev0m+0c07eb350 Maven dependency. How to use oop-lib-jvm version 0.31.5-dev0m+0c07eb350 in pom.xml?
( it.unibo.tuprolog - oop-lib-jvm version 0.31.5-dev0m+0c07eb350 ) in their Java...; it.unibo.tuprolog - oop-lib-jvm version 0.31.5-dev0m+0c07eb350 java library...it.unibo.tuprolog  - Version 0.31.5-dev0m+0c07eb350 of oop-lib-jvm Maven
Maven Repository/Dependency: it.unibo.tuprolog | oop-lib-jvm
Maven Repository/Dependency of Group ID it.unibo.tuprolog and Artifact ID oop-lib-jvm. Latest version of it.unibo.tuprolog:oop-lib-jvm dependencies. # Version Release Date 1
OOP
OOP       OOPs stands... the object creation process, programmatically. Read more at : www.roseindia.net/java/beginners/oop-in-java.shtmlADS_TO_REPLACE_1
Java Array Length
Java Array Length       In this section, you will learn about the java array length. The java array... not be altered when required.ADS_TO_REPLACE_1 The Array class implicitly extends
Java Array Length
Java Array Length In this section you will find a program to find the length of array in java. An array is collection of similar data type. To find the length of array is a simple program in java. Using length function you can find
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.16.0 is released. Learn to use oop-lib-jvm version 0.16.0 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.16.0 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.16.0 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.16.1 is released. Learn to use oop-lib-jvm version 0.16.1 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.16.1 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.16.1 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.0 is released. Learn to use oop-lib-jvm version 0.17.0 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.0 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.17.0 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.1 is released. Learn to use oop-lib-jvm version 0.17.1 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.1 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.17.1 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm
Maven dependency for it.unibo.tuprolog - oop-lib-jvm version 0.17.2 is released. Learn to use oop-lib-jvm version 0.17.2 in Maven based Java projects
; it.unibo.tuprolog - oop-lib-jvm version 0.17.2 in Java projects. Follow the step by step...Maven dependency for  it.unibo.tuprolog  - Version 0.17.2 of oop-lib-jvm released The developers of   it.unibo.tuprolog - oop-lib-jvm

Ads