Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
public class ParkingLotApplication {
 static Scanner input= new Scanner(System.in);
 public static ParkingDescription[][] ParkingLot = new ParkingDescription[3][15];
 public StudentDescription StudDesc = new StudentDescription();
 static int i=0;
 static int j=0;
 static int parkLevel=0;
 static int parkSlot=0;

public static void main(String[] args) {
// TODO: Add your code here
ParkingLotApplication PA = new ParkingLotApplication();
PA.menu();
 }
public void menu()
 {
Scanner input= new Scanner(System.in);
System.out.println("WELCOME TO CAR PARK SYSTEM");
System.out.println("Enter your name: ");
String nm= input.nextLine();
System.out.println("Enter your password: ");
int pass= input.nextInt();
if((nm.equals("admin12")) && (pass==12345))
{
  Login();
}
else
{
  menu();
}
   }
  public void Login()
 {
    System.out.println("|----------------------------------|");
    System.out.println("|           Admin Menu             |");
    System.out.println("|----------------------------------|");
    System.out.println("|  N- New Registration             |");
    System.out.println("|  U- Update Data                  |");
    System.out.println("|----------------------------------|");
    char ch= input.next().charAt(0);
    switch(ch)
    {
      case 'N':
      case 'n': Reg();
      break;

      case 'U':
        case 'u': UpdatePark();
        break;


      default:
        System.out.println("Choose Again!");
        Login();
        break;
    }
  }
  public void Reg()
  {
System.out.println ();
System.out.println ("                               **Parking Lot**        ");
System.out.println ("    ________________________________________________________________________________");
  for ( i = 0; i<3; i++) {
    for ( j = 0; j<15; j++) {
      ParkingLot[i][j] = new ParkingDescription();
      System.out.print ("   *   "  +ParkingLot[i][j].getStatus());}
    System.out.println ();
System.out.println ("    ********************************************************************************");
}
System.out.println("Please insert number 1-3 to choose the parking level");
parkLevel = input.nextInt();
System.out.println("Please insert number 1-15 to choose the parking slot");
parkSlot = input.nextInt();

//check available
if(parkLevel == 1)
{
  ParkingLot[0][parkSlot-1] = new ParkingDescription();
  if(ParkingLot[0][parkSlot-1].getAvailable() == true )
  {
    System.out.println("Please Enter tp: ");
      int tp= input.nextInt();
      System.out.println("Please Enter First Name: ");
      String ft= input.next();
      System.out.println("Please Enter Last Name: ");
      String lt= input.next();
      System.out.println("Please Enter Contact Number: ");
      int cn= input.nextInt();
      System.out.println("Please Enter Email Address: ");
      String ea= input.next();
      System.out.println("Please Enter Car Number: ");
      String cnb= input.next();
      System.out.println("Please Enter Date Registered : ");
      int date= input.nextInt();

      StudDesc.setStudDesc(tp, ft, lt, cn, ea, cnb, date);

      int pID = (parkLevel*1000) + parkSlot;
      ParkingLot[0][parkSlot-1].setPark(pID, false,StudDesc);
      System.out.println("Thanks");
      menu();
  }else {
    System.out.println("Sorry");
      menu();
  }
}
else if(parkLevel == 2)
{
  ParkingLot[1][parkSlot-1] = new ParkingDescription();
  if(ParkingLot[1][parkSlot-1].getAvailable() == true )
  {
    System.out.println("Please Enter tp: ");
      int tp= input.nextInt();
      System.out.println("Please Enter First Name: ");
      String ft= input.next();
      System.out.println("Please Enter Last Name: ");
      String lt= input.next();
      System.out.println("Please Enter Contact Number: ");
      int cn= input.nextInt();
      System.out.println("Please Enter Email Address: ");
      String ea= input.next();
      System.out.println("Please Enter Car Number: ");
      String cnb= input.next();
      System.out.println("Please Enter Date Registered : ");
      int date= input.nextInt();

      StudDesc.setStudDesc(tp, ft, lt, cn, ea, cnb, date);

      int pID = (parkLevel*1000) + parkSlot;
      ParkingLot[1][parkSlot-1].setPark(pID, false,StudDesc);
      System.out.println("Thanks");
      menu();
  }else {
    System.out.println("Sorry");
      menu();
  }
}

else if(parkLevel == 3)
{
  ParkingLot[2][parkSlot-1] = new ParkingDescription();
  if(ParkingLot[2][parkSlot-1].getAvailable() == true )
  {
    System.out.println("Please Enter tp: ");
      int tp= input.nextInt();
      System.out.println("Please Enter First Name: ");
      String ft= input.next();
      System.out.println("Please Enter Last Name: ");
      String lt= input.next();
      System.out.println("Please Enter Contact Number: ");
      int cn= input.nextInt();
      System.out.println("Please Enter Email Address: ");
      String ea= input.next();
      System.out.println("Please Enter Car Number: ");
      String cnb= input.next();
      System.out.println("Please Enter Date Registered : ");
      int date= input.nextInt();

      StudDesc.setStudDesc(tp, ft, lt, cn, ea, cnb, date);

      int pID = (parkLevel*1000) + parkSlot;
      ParkingLot[2][parkSlot-1].setPark(pID, false, StudDesc);
      System.out.println("Thanks");
      menu();
  }else {
    System.out.println("Sorry");
      menu();
  }
}
 }
  public void UpdatePark()
 {
System.out.println ();
System.out.println ("                                     **Parking Lot**                   ");
System.out.println ("    ________________________________________________________________________________");
  for ( i = 0; i<3; i++) {
    for ( j = 0; j<15; j++) {
      ParkingLot[i][j] = new ParkingDescription();
      System.out.print ("   *   "  +ParkingLot[i][j].getStatus());}
    System.out.println ();
System.out.println ("    ********************************************************************************");
}
System.out.println("Please insert number 1-3 to choose the parking level");
parkLevel = input.nextInt();
System.out.println("Please insert number 1-15 to choose the parking slot");
parkSlot = input.nextInt();

//check available
if(parkLevel == 1)
{
  ParkingLot[0][parkSlot-1] = new ParkingDescription();
  if(ParkingLot[0][parkSlot-1].getAvailable() == false )
  {
    ParkingLot[0][parkSlot-1].showDetails();
      menu();
  }else {
    System.out.println("Sorry");
      menu();
  }
}
else if(parkLevel == 2)
{
  ParkingLot[1][parkSlot-1] = new ParkingDescription();
  if(ParkingLot[1][parkSlot-1].getAvailable() == true )
  {
    ParkingLot[1][parkSlot-1].showDetails();
      menu();
  }else {
    System.out.println("Sorry");
      menu();
  }
}

else if(parkLevel == 3)
{
  ParkingLot[2][parkSlot-1] = new ParkingDescription();
  if(ParkingLot[2][parkSlot-1].getAvailable() == true )
  {
    ParkingLot[2][parkSlot-1].showDetails();
      menu();
  }else {
    System.out.println("Sorry");
      menu();
  }
}

}

} I have this problem. when i want to set one parking detail object into ParkingLot array, the array is insert same data information on all of array. the output suppose to be like this:

Parking Lot
* 1 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0

but I got all the output being set to 1. So how to solve this problem? thanks..

share|improve this question
 
Can you show us all of your code please? Not just the part where YOU think the problem is? –  David Wallace 20 mins ago
 
i already edited my code above. please check again. thanks.. –  user3079530 9 mins ago
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.