-3

A code returns error <identifier> expected. I don't know why this error is occuring.

package com.company;


import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        intro();
        time();
    }

    public static void intro() {

        System.out.println("Welcome");
        System.out.println("What is your name");
        Scanner input = new Scanner(System.in);

        String name = input.nextLine();
        System.out.println("Nice to meet you," + name + " where are you travelling to?");
        String dest = input.nextLine();
        System.out.println("Great!" + dest + " sounds like a great trip");
    }

    public static void time() {
        Scanner input = new Scanner(System.in);

        int hours, minutes;
        float perd, perdc, change;

        System.out.println("How many days are you going to spend travelling?");

        int days = input.nextInt();

        hours = days * 24;
        minutes = hours * 60;

        System.out.println("How much money in USD are you going to spend?");

        Double money = input.nextDouble();
        perd = (money / days);

        System.out.println("What is the three letter currency symbol of your destination?");

        String curr = input.nextLine();

        System.out.println("How many" + curr + "are there in 1USD?");

        Double ex = input.double();
        change = money * ex;
        perdc = perd * ex;

        System.out.println("If you are travelling for" + days + "that is the same as" + hours + "or" + minutes + "minutes");
        System.out.println("If you are going to spend" + money + "$USD that means per day you can spend upto $" + perd + "USD");
        System.out.println("Your total budget in" + ex + "is" + change + ex + ",which per day is  " + perdc + curr);
    }
}
jonrsharpe
  • 99,167
  • 19
  • 183
  • 334
slims8033
  • 3
  • 1
  • 1
  • 3
    When asking about build error, always include the *full* and *complete* error output. And add a comment in the shown code where the errors are (line numbers are usually reported in the message). Also please take some time to read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Sep 30 '19 at 12:57
  • hours, minutes etc need to be declared as a variable type. – Deane Kane Sep 30 '19 at 12:59
  • 1
    @DeaneKane The declaration exists. – Tom Sep 30 '19 at 13:01
  • 2
    The documentation for `Scanner` is neither hard to find nor complicated to read, so I really wonder how you came up with `input.double()` or `input.int()`. – Tom Sep 30 '19 at 13:03

1 Answers1

2

I'am glad to see peaple learning Java, and i'am happy to see peaople helping the juniors. When i see your code, my first advise is to get a good IDE like Eclipse, IntelliJ or Netbeans, it will help you to see quickly the compilation errors.

My second advise is to get a look to the dev norms, as a junior i think is the first methodology you have to study to have a comprehensive and maintainable code.

for example please avoid adding several blank lines between the method signature and the first statment. I barely touched your code to get it works. I hope you will enjoy Java.

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        intro(input);
        time(input);
    }

    public static void intro(Scanner input) {
        System.out.println("Welcome");
        System.out.println("What is your name");

        String name = input.nextLine();
        System.out.println("Nice to meet you, " + name + " where are you travelling to?");
        String dest = input.nextLine();
        System.out.println("Great! " + dest + " sounds like a great trip");
    }

    public static void time(Scanner input) {
        int hours, minutes;
        float perd, perdc, change;

        System.out.println("How many days are you going to spend travelling?");

        int days = input.nextInt();

        hours = days * 24;
        minutes = hours * 60;

        System.out.println("How much money in USD are you going to spend?");

        Float money = input.nextFloat();
        perd = money / days;

        System.out.println("What is the three letter currency symbol of your destination?");

        String curr = input.nextLine();

        System.out.println("How many " + curr + " are there in 1USD?");

        Float ex = input.nextFloat();
        change = money * ex;
        perdc = perd * ex;

        System.out.println("If you are travelling for " + days + " that is the same as " + hours + " or " + minutes + " minutes");
        System.out.println("If you are going to spend " + money + " $USD that means per day you can spend upto $" + perd + " USD");
        System.out.println("Your total budget in " + ex + " is " + change + ex + " ,which per day is  " + perdc + curr);
    }
heyhooo
  • 82
  • 6