Posted by: Brain Malfunction July 17, 2008
Java help
Login in to Rate this Post:     0       ?        

 

Score,

 Following is C++ code, you can certainly see what is going on because JAVA is similar syntax. Plus both languages speak English too.

Or ask for some JAVA GURU of SAJHA for translation..

hope it helps you!

 

#include <iostream>
using namespace std;

#include <cctype>
using std::toupper;

int main()
{
   const int SEATS = 11;
   int flight[ SEATS ] = { 0 };
   int passenger = 0;  
   int coach = 6;
   int firstClass = 1;
   int choice;
   char response;
  

        while ( passenger < 10 )
        {
          cout << "\nPress 1 for \"The Creamy Front Seats\"\n"
         << "Press 2 for \"Old and Dirty Back Seats\"\n";
        cin >> choice;

        if ( choice == 1 )
      {
             if ( !flight[ firstClass ] && firstClass <= 5 ) //first class available seating
         {
            cout << "Your seat is " << firstClass
               << " in the Super Sweet Front Section.\n";
            flight[ firstClass++ ] = 1;
            passenger++;
             } // end if

            else if ( firstClass > 5 && coach <= 10 ) // take economy seating
         {    
                cout << "The Ultra Kewl People section is full.\nWould you "
                   << "like to sit With the Animals (Y or N)? ";
                cin >> response;
    
            
            if ( toupper( response ) == 'Y' )
            {
               cout << "Your seat is " << coach
                  << " in the Back Half of The Plane.\n";
               flight[ coach++ ] = 1;
               passenger++;
            } // end if
            else
               cout << "Next flight in 3 hours so you'd better hurry up.\n";
         } // end outer else
           else
            cout << "Next flight in 3 hours this means you.\n";
       } // end outer if
       else
          {
            if ( !flight[ coach ] && coach <= 10 ) // seat available
         {
            cout << "Your seat is " << coach
               << " in the crappy part of town.\n";
            flight[ coach++ ] = 1;
            passenger++;
         } // end if
         else if ( firstClass <= 5 )
             {
            cout << "The poor people section is full.\nWould you like "
                 << "to sit in the upperclass section (Y or N)? ";
            cin >> response;

              if ( toupper( response ) == 'Y' )
            {
               cout << "Your seat is " << firstClass
                  << " in the rich part of town.\n";
               flight[ firstClass++ ] = 1;
               passenger++;
              } // end if
            else
               cout << "Next flight in 3 hours you'd better hurry up.\n";
           } // end outer else
         else
            cout << "Next flight in 3 hours put a rush on that.\n";
         } // end outer if
     } // end while

   cout << "All of the seats are gone, sorry but you suck." << endl;
   return 0;
    }

Read Full Discussion Thread for this article