8 Replies - 263 Views - Last Post: 28 April 2019 - 12:43 AM Rate Topic: -----

#1 cr7rak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-April 19

how to get date format,

Posted 27 April 2019 - 06:47 AM

I make booking program with this program after running everything is fine but when I typed date for ex(aug-10-2019) it's coming error message the error is Enter your check-in date:

august-20-1990
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:91)
exit status 1

program below
import java.util.Scanner;

import sun.management.counter.Variability;
class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);

    //declare variables 
    char option; 
    char hotel_menu;
    char room;
    char room_no;
    char visitors;
    int check_in;
    int check_out;
    
    System.out.println("\ta: Visitors");
    System.out.println("\tb: Employees");



    //get the selected option
    hotel_menu = s.next().charAt(0);

    // display the menu 
    System.out.println("Please select an option or \"x\" to exit:");
    System.out.println("\ta: Select room type ");
    System.out.println("\tb: Number of rooms");
    System.out.println("\tc: Visitors");
    System.out.println("\td: Check in date");
    System.out.println("\te: Check out date");



    //get the selected option
    
    option = s.next().charAt(0);

    //check the selected option

    switch(option){
      case'a':
      case'A':
        System.out.println("Please type your room type:");
         
           System.out.println("a: Single");
            System.out.println("b: Double");
            System.out.println("c: Triple");
            System.out.println("d: Quad");
            System.out.println("e: Queen");
            System.out.println("f: King");
            System.out.println("g: Twin");
            System.out.println("h: Twin Double");
            System.out.println("q: Quit");

          room = s.next().charAt(0);
        
        
        System.out.println("Your room type is "+ room);
        
        
      
      
       break;

      case'b':
      case'B':
        System.out.println("Please enter number of rooms");
        
        room_no = s.next().charAt(0);
        
        System.out.println("The number of rooms you have booked are:"+ room_no);
        

        break;

      case'c':
      case'C':
        System.out.println("Enter the number of visitors:");
        
        visitors = s.next().charAt(0);
        System.out.println(visitors+"\tvistors have booked a room in the hotel");
        

        break;

      case'd':
      case'D':
       System.out.println("Enter your check-in date:");

        check_in = s.nextInt();

        System.out.println("Your scheduled check-in date is:" + check_in);
        check_in = s.nextInt();

        break;
        case'e':
      case'E':
       System.out.println("Enter your check-out date:");

        check_out = s.nextInt();

        System.out.println("Your scheduled check-out date is:" + check_out);
        check_out = s.nextInt();

      
     }

  }
}
:code:

This post has been edited by modi123_1: 27 April 2019 - 08:32 AM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: how to get date format,

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14995
  • View blog
  • Posts: 59,874
  • Joined: 12-June 08

Re: how to get date format,

Posted 27 April 2019 - 08:33 AM

If you are inputting a date, would 'next integer' seem reasonable to use?
091	        check_in = s.nextInt();

Was This Post Helpful? 0
  • +
  • -

#3 cr7rak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-April 19

Re: how to get date format,

Posted 27 April 2019 - 08:36 AM

View Postmodi123_1, on 27 April 2019 - 08:33 AM, said:

If you are inputting a date, would 'next integer' seem reasonable to use?
091	        check_in = s.nextInt();


when I type number it's coming your booking date is 2 but I want in date format . can you help me pelease
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14995
  • View blog
  • Posts: 59,874
  • Joined: 12-June 08

Re: how to get date format,

Posted 27 April 2019 - 08:42 AM

I would think about getting the '.next' value in a string and converting that to date time.
https://docs.oracle....il/Scanner.html
Was This Post Helpful? 0
  • +
  • -

#5 cr7rak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-April 19

Re: how to get date format,

Posted 27 April 2019 - 10:51 AM

View Postmodi123_1, on 27 April 2019 - 08:42 AM, said:

I would think about getting the '.next' value in a string and converting that to date time.
https://docs.oracle....il/Scanner.html


still I facing error please some one help in this stuff.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14995
  • View blog
  • Posts: 59,874
  • Joined: 12-June 08

Re: how to get date format,

Posted 27 April 2019 - 10:56 AM

Just noticed - this is in the wrong forum. Java is NOT javascript.

Let's see your current code where you are not using 'next int' when getting in a string on line 91.

Also copy/paste any new errors.
Was This Post Helpful? 0
  • +
  • -

#7 cr7rak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-April 19

Re: how to get date format,

Posted 27 April 2019 - 01:00 PM

View Postmodi123_1, on 27 April 2019 - 10:56 AM, said:

Just noticed - this is in the wrong forum. Java is NOT javascript.

Let's see your current code where you are not using 'next int' when getting in a string on line 91.

Also copy/paste any new errors.


this is my codes
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);

//declare variables
char option;
char hotel_menu;
char room;
char room_no;
char visitors;
int check_in;
int check_out;

System.out.println("\ta: Visitors");
System.out.println("\tb: Employees");



//get the selected option
hotel_menu = s.next().charAt(0);

// display the menu
System.out.println("Please select an option or \"x\" to exit:");
System.out.println("\ta: Select room type ");
System.out.println("\tb: Number of rooms");
System.out.println("\tc: Visitors");
System.out.println("\td: Check in date");
System.out.println("\te: Check out date");



//get the selected option
option = s.next().charAt(0);

//check the selected option

switch(option){
case'a':
case'A':
System.out.println("Please type your room type:");
System.out.println("a: Single");
System.out.println("b: Double");
System.out.println("c: Triple");
System.out.println("d: Quad");
System.out.println("e: Queen");
System.out.println("f: King");
System.out.println("g: Twin");
System.out.println("h: Twin Double");
System.out.println("q: Quit");

room = s.next().charAt(0);
System.out.println("Your room type is "+ room);
break;

case'b':
case'B':
System.out.println("Please enter number of rooms");
room_no = s.next().charAt(0);
System.out.println("The number of rooms you have booked are:"+ room_no);

break;

case'c':
case'C':
System.out.println("Enter the number of visitors:");
visitors = s.next().charAt(0);
System.out.println(visitors+"\tvistors have booked a room in the hotel");

break;

case'd':
case'D':
System.out.println("Enter your check-in date:");

check_in = s.nextInt();

System.out.println("Your scheduled check-in date is:" + check_in);
check_in = s.nextInt();

break;
case'e':
case'E':
System.out.println("Enter your check-out date:");

check_out = s.nextInt();

System.out.println("Your scheduled check-out date is:" + check_out);
check_out = s.nextInt();

}

}
}
Was This Post Helpful? 0
  • +
  • -

#8 cr7rak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-April 19

Re: how to get date format,

Posted 27 April 2019 - 01:09 PM

this is new coding now i'm getting this error after running
Main.java:32: error: : expected
case 2;
^
1 error
compiler exit status 1


import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);

//declare variables
char option;
char hotel_menu;
char room;
char room_no;
char visitors;
char Employees;
int check_in;
int check_out;

System.out.println("\ta: Visitors");
System.out.println("\tb: Employees");
int option=input.nextInt();
switch (option){
case 1:
//get the selected option
hotel_menu = s.next().charAt(0);

// display the menu
System.out.println("Please select an option or \"x\" to exit:");
System.out.println("\ta: Select room type ");
System.out.println("\tb: Number of rooms");
System.out.println("\tc: Visitors");
System.out.println("\td: Check in date");
System.out.println("\te: Check out date");
break;
case 2;
System.out.println("\ta: name");
System.out.println("\tb: job");
break;
//get the selected option
option = s.next().charAt(0);

//check the selected option

switch(option){
case'a':
case'A':
System.out.println("Please type your room type:");
System.out.println("a: Single");
System.out.println("b: Double");
System.out.println("c: Triple");
System.out.println("d: Quad");
System.out.println("e: Queen");
System.out.println("f: King");
System.out.println("g: Twin");
System.out.println("h: Twin Double");
System.out.println("q: Quit");

room = s.next().charAt(0);
System.out.println("Your room type is "+ room);
break;

case'b':
case'B':
System.out.println("Please enter number of rooms");
room_no = s.next().charAt(0);
System.out.println("The number of rooms you have booked are:"+ room_no);

break;

case'c':
case'C':
System.out.println("Enter the number of visitors:");
visitors = s.next().charAt(0);
System.out.println(visitors+"\tvistors have booked a room in the hotel");

break;

case'd':
case'D':
System.out.println("Enter your check-in date:");

check_in = s.nextInt();

System.out.println("Your scheduled check-in date is:" + check_in);
check_in = s.nextInt();

break;
case'e':
case'E':
System.out.println("Enter your check-out date:");

check_out = s.nextInt();

System.out.println("Your scheduled check-out date is:" + check_out);
check_out = s.nextInt();

}
}
}
}
Was This Post Helpful? 0
  • +
  • -

#9 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3627
  • View blog
  • Posts: 16,660
  • Joined: 20-September 08

Re: how to get date format,

Posted 28 April 2019 - 12:43 AM

Quote

Main.java:32: error: : expected
case 2;


If you look carefully you will see that the punctuation mark there is different from your other (proper) case ones
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1