title: Java - Code skips an input
body: <p>I was tasked with creating a small application for college, and have created a simple booking system. 
  I'm having an issue in that when the program runs, for no reason i can fathom it's executing the print part of a method but then jumping to the next method without executing the in.next() part of the original method.</p>
  
  <p>I've included here in order the abstract class, the class where the issue is occuring, the menu and the 'Creation' class.</p>
  
  <p>I've been informed before here my coding (at least naming conventions) are not the best so i apologize for this in advance.</p>
  
  <p>When i altered the class so that wasn't an extension of raw_Booking it seemed to not have this issue but not sure if that's relevant.</p>
  
  <pre><code>import java.util.Scanner;
  
  
  abstract class raw_Booking {
  
  
  private static String fname;
  private static String lname;
  private static int HouseNo;
  private static String Street;
  private static String Postcode;
  
  
  Scanner in = new Scanner(System.in);
  
  
  raw_Booking(){
  
  
  }
  
  abstract public String Setfname();
  abstract public String Setlname();
  abstract public int SetHouseNo();
  abstract public String SetStreet();
  abstract public String SetPostcode();
  abstract public String Verification();
  
  
  
  }
  </code></pre>
  
  <p>The problem class (method is SetPostcode):</p>
  
  <pre><code>import java.util.Scanner;
  import java.io.*;
  
  class Hotel_Booking extends raw_Booking{
  
  
  
  Scanner in = new Scanner(System.in);
  
  private String TheVerification;
  private int guests;
  private String Roomtype;
  private double numbRooms;
  private double costStay;
  private double nights;
  private static String fname;
  private static String lname;
  private static int HouseNo;
  private static String Street;
  private static String Postcode;
  
  Hotel_Booking() {
  
      fname = Setfname();  
      lname = Setlname();
      HouseNo = SetHouseNo();
      Street = SetStreet();
      Postcode = SetPostcode();
      TheVerification = Verification();
      Roomtype = setRoomtype();
      guests = guests();
      numbRooms = numbRooms();
      nights = nights();
      costStay = costStay();
      Write_File();
  }
  
  
  public String Setfname(){
      System.out.println();
      System.out.print("Bookers first name please:   ");
      fname = in.next();
      return fname;
  }
  
  public String Setlname(){
  
      System.out.println();
      System.out.print("Bookers surname please:   ");
      lname = in.next();
      return lname;
  }
  
  public int SetHouseNo(){
     Scanner sc = new Scanner(System.in);
     System.out.println();
     System.out.print("Please enter your house number:   ");
     while (!sc.hasNextInt()) {
         System.out.println();
         System.out.print("You need to enter a number - please re-enter:   ");
         sc.next();
     }
  return sc.nextInt();
  }
  
  
  public String SetStreet(){
      System.out.println();
      System.out.print("Please enter your street:   ");
      Street =in.next();
      return Street;
  }
  
  public String SetPostcode(){
  
      System.out.println();
      System.out.print("Please enter your postcode:   ");
      Postcode = in.next();
      return Postcode;
  }
  
  
  public String Verification(){
  
      System.out.println();
      System.out.print("Please provide your car reg as verification:   ");
      TheVerification = in.next();
      return TheVerification;
  
  }
  
  public String setRoomtype(){  
  
      System.out.println();
      System.out.print("Would you like a Premiun or Regular room(s)?   ");
      Roomtype = in.next();
      return Roomtype;
  }
  
  public int guests(){
  
      System.out.println();
      System.out.print("How many guests will be staying?   ");
      guests = in.nextInt();
      return guests;
  
  }
  //For every 3 guests their must be 1 room at £50 per night.
  //Premiun rooms = price doubled
  
  public double numbRooms(){
  
     for(int i=0;i &lt; guests;i++){
         numbRooms = numbRooms+1;
         i = i + 2;
      }
     System.out.println();
     System.out.println("You will require " + numbRooms + " number of rooms");
     return numbRooms;
  }
  
  public double nights(){
  
      System.out.println();
      System.out.print("How many nights are you staying?   ");
      nights = in.nextDouble();
      return nights;
  }
  
  public double costStay(){
  
      if(Roomtype.equals("Regular")){
          costStay = (nights * numbRooms)*50;
      }
      else{
          costStay = (nights * numbRooms)*100;
      }
      System.out.println();
      System.out.println("The total cost of your stay will be: " + costStay);
      return costStay;
  }
  
  public void Write_File(){
      System.out.println();
      System.out.println("Your details will now be written to file.");
      System.out.println();
      try{
          PrintWriter wr = new PrintWriter(new    FileOutputStream("Hotel_Booking.txt",true));
          wr.println("Name: " + fname+ " " + lname);
          wr.println("Address line one: " + HouseNo + " " + Street);
          wr.println("Postcode: " + Postcode);
          wr.println("Roomtype: " + Roomtype);
          wr.println("Number of rooms: " + numbRooms);
          wr.println("Nights staying: " + nights);
          wr.println("Total cost of stay: " + costStay);
          wr.close();
         }
  
      catch (IOException e){
          System.out.println("Error -- " + e.toString());
          }
  
  }
  public static String Getfname(){
      return fname;
  }
  
   }
  </code></pre>
  
  <p>Contains Interface/Menu..</p>
  
  <pre><code>public class Interface{
  
  
  
   public static void Menu(){
  
      System.out.println("Welcome to the booking system select an option");
      System.out.println("1 - Create a new hotel booking");
      System.out.println("2 - Create a new airline booking");
      System.out.println("3 - Create a car hire booking");
      System.out.println("4 - Create a amusement park ticket booking");
      System.out.println("5 - Create a concert ticket booking");
      System.out.println();
  
  
  
  
  }
  
  }
  </code></pre>
  
  <p>Main point of execution:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  public class Booking_Creation{
  
  static Scanner in = new Scanner(System.in);    
  
  static ArrayList&lt;Hotel_Booking&gt; hotelbookings = new ArrayList&lt;Hotel_Booking&gt;();
  static ArrayList&lt;Flight_Booking&gt; flightbookings = new ArrayList&lt;Flight_Booking&gt;();
  static ArrayList&lt;Car_Hire&gt; carhirebookings = new ArrayList&lt;Car_Hire&gt;();
  static ArrayList&lt;Amusement_Park_Ticket&gt; parkticket = new ArrayList&lt;Amusement_Park_Ticket&gt;();
  static ArrayList&lt;Concert_Ticket&gt; concertticket = new ArrayList&lt;Concert_Ticket&gt;();
  
  
  
  static int selection;
  public static void main(String[] arguments){
  
      Interface.Menu();
  
      selection = in.nextInt();
  
      // COULD ASK THE QUESTIONS HERE????
      /// BUT THE INPUT BIT IS INSIDE THE OTHER CLASS
  
  
  
      switch(selection){
              case 1:
              Hotel_Booking hb = new Hotel_Booking();
              hotelbookings.add(hb);
              break;
              case 2:
              Flight_Booking fb = new Flight_Booking();
              flightbookings.add(fb);
              break;
              case 3:
              Car_Hire ch = new Car_Hire();
              carhirebookings.add(ch);
              break;
              case 4:
              Amusement_Park_Ticket pt = new Amusement_Park_Ticket();
              parkticket.add(pt);
              break;
              case 5:
              Concert_Ticket ct = new Concert_Ticket();
              concertticket.add(ct);
              break;
          }
  
  
  }
  }
  </code></pre>
  
  <p>Example output:</p>
  
  <pre><code>Welcome to the booking system select an option
  1 - Create a new hotel booking
  2 - Create a new airline booking
  3 - Create a car hire booking
  4 - Create a amusement park ticket booking
  5 - Create a concert ticket booking
  
  1
  
  Bookers first name please:   Herton
  
  Bookers surname please:   Ferford
  
  Please enter your house number:   4
  
  Please enter your street:   Park Lane
  
  Please enter your postcode:   
  Please provide your car reg as verification:  KS23
  </code></pre>
  
  <p>Regards in advance.</p>