Home Answers Viewqa Java-Beginners OOP with Java-Array

 
 


leowlinfang
OOP with Java-Array
1 Answer(s)      4 years and 3 months ago
Posted in : Java Beginners

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 Pages:
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
oop  can you tell me about why java is not 100% object oriented language
OOP
OOP
OOP   OO Analysis & Design Classes represent domain elements. May... classes UML is most common visual modelling technique is-a vs has-a Java... a home to utility functions. Create immutable objects. Java 5 autoboxing
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
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
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
OOP
OOP       OOPs stands... the object creation process, programmatically. Read more at : www.roseindia.net/java/beginners/oop-in-java.shtml
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 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  write a java method that takes an array of float values...)){ System.out.println("There are duplicate elements."); Float array...++){ array[i]=new Float(arr[i]); } Set<Float>
java array
java array  q4.array Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds
Java Array
Java Array   a) Write an array program that perform the following: i) Declares a String array initialized with the following strings: ââ?¬Å...?¬Â?. ii) Write a loop that displays the contents of each element in the array
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
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 the question. Write a program to assign passengers seats in an airplane
OOP - Java Beginners
); } For more information on Java visit to : http://www.roseindia.net/java/ http://www.roseindia.net/java/beginners/Construct.shtml Thanks
OOP - Java Beginners
OOP  I am having difficulty in the following program: Create a client program for the class clock that creates an array of Clock objects for the times 5:32:00 8:22:8 23:7:34 4:49:49 12:2:12 . Print the array elements
java"oop" - Java Beginners
Java OOPs Concept  What is OOPs programming and what it has to do with the Java?  Hi i hope you understand it.//To print the even numbers...){ System.out.println(e); } }}Java program to display all even numbers http
java oop - Java Beginners
java oop  Consider the following declarations: { private int u... 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 statement
JAVA OOP - Java Beginners
JAVA OOP  Employees in a company are divided into the classes... to construct a one-dimensional array containing an increasing annual salary scale, each subscript to the array equates to an incremental point on the salary scale
OOP - Java Beginners
OOP  Which one is better to learn object oriented progamming java or c++? thaks, Bet.  Hello, As of my concern both have different scope and use, you can not merge these. As i java person so i will show you 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 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
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 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
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
OOP Tutorial [first draft]
Java: OOP Tutorial [first draft] Table of contents Introduction.... These notes are about programming and Java language features necessary for OOP, and do...-Oriented Design (OOD) and Object-Oriented Programming (OOP) An important part
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 - Java Beginners
Java Array  Q1-Write a program to exchange non diagonal elements of two dimensinal NXN Array without using temporary array  Hi Friend, Please try the following code to solve your problem. Here is the code: class
Java Array - Java Beginners
Java Array  Can someone help me to convert this to java? I have an array called Projects{"School", "House", "Bar"} I want all the possible combinations but only once each pair, for example ["House", "Bar"] is the SAME
Java Array - Java Beginners
Java Array  Q4-Write a program to exchange the nondiognal elements of a two dimensional array A of size NxN without using any other array ie. each a[i][j]with a[j][i] where i is not equal j?   Hi Friend, Please try
java array - Java Beginners
java array  1.) Consider the method headings: void funcOne(int[] alpha, int size) int funcSum(int x,int y) void funcTwo(int[] alpha, int[] beta...]; int num; Write Java statements that do the following: a. Call
Java array - Java Beginners
Java array  Q 1- write a program that counts the frequency... a program tofind sum of all non dioganal elements of a two dimensional NxN array... array A of size NxN without using any other array ie. each a[i][j]witha[j][i
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
Object-Oriented Programming
Java: Object-Oriented Programming Beyond OOP Here's an interesting article about going beyond OOP: The Next Move in Programming: A Conversation with Sun's Victoria Livschitz at java.sun.com/developer/technicalArticles/Interviews

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.