OOP with Java-Array

Ads

 
 

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

Ads









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
Java array
Java array   How can one prove that the array is not null but empty
Advertisements
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
oop
oop  can you tell me about why java is not 100% object oriented language
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 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 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
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
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 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 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
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 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 - 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
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
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
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
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 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
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 Length
Java Array Length       In this section, you will learn about the java array length. The java array... about array click on: http:/www.roseindia.net/java/language/introduction-to-java
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
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

Ads

 
Advertisement null

Ads