eclipse - java - errors

0

Can someone help me to find the error of this code

package trab;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;
import java.util.TimeZone;

public class tra {

    public static void main(String[] args) {
        //new janela();//
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Brazil/East"));
        int hora = calendar.get(Calendar.HOUR_OF_DAY);
        int minuto = calendar.get(Calendar.MINUTE);

    Scanner s = new Scanner(System.in);
    int [] p = new int [5];
    int [] aux = new int [5]; 
        for (int i=0; i<5;i++) {
            System.out.println("faça seu pedido! as opções de hoje no cardapio são: "
            + "\n 1- X hamburguer de rato "//demora 20 minutos
            + "\n 2- X filé de grilo "//demora 20 minutos
            + "\n 3- X queijo de cobra "//demora 10 minutos
            + "\n 4- X lonbinho de elefante "//demora 40 minutos
            + "\n 5- X vegetariano (a melhor opção ) "//demora 10 minutos
            + "\n 6- sopa de minhoca");//demora 1 hora
            p[i]=s.nextInt();
        }
    merge(p,aux, 0,p.length-1);
    System.out.println(Arrays.toString(p));

        private static void merge(int[] p, int[] aux, int inicio, int fim) {
            if (incio<fim) {
             int meio=inicio+fim/2;
              merge(p,aux,inicio,meio);
              merge(p,aux,meio+1,fim);
              intercalar(p,aux,inicio,meio,fim);
            }

        }
    }

    private static void intercalar(int[] p, int[] aux, int inicio, int meio, int fim) {
        for(int i=inicio;i<=fim;i++) 
            aux[i]=p[i];
            int k=inicio;
            int j=meio+1;


        for(int i=inicio;i<=fim;i++) {
            if(k>meio) {
                p[i]=aux[j++];
            }
            if(j>fim){
                p[i]=aux[k++];
            }
            if(p[i]<aux[j]){
                p[i]=aux[i++];
            }
            else {
                p[i]=aux[j++]
            }
        }
    }

}

When I try to run it, this message appears

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The method merge(int[], int[], int, int) is undefined for the type tra
void is an invalid type for the variable merge
Syntax error on token "(", ; expected
Duplicate local variable p
Syntax error on token ",", ; expected
Duplicate local variable aux
Syntax error on token ",", ; expected
Syntax error on token ",", ; expected
Syntax error on token ")", ; expected
incio cannot be resolved to a variable
The method merge(int[], int[], int, int) is undefined for the type tra
The method merge(int[], int[], int, int) is undefined for the type tra

at trab.tra.main(tra.java:29)
    
asked by anonymous 22.11.2017 / 00:46

1 answer

2

As it seems to me, you have to get the method: merge(int[], int[], int, int) from within method main(String[] args) . As below:

package trab;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;
import java.util.TimeZone;

public class tra {

    public static void main(String[] args) {
            //new janela();//
            Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Brazil/East"));
            int hora = calendar.get(Calendar.HOUR_OF_DAY);
            int minuto = calendar.get(Calendar.MINUTE);

            Scanner s = new Scanner(System.in);
            int [] p = new int [5];
            int [] aux = new int [5]; 
            for (int i=0; i<5;i++) {
                System.out.println("faça seu pedido! as opções de hoje no cardapio são: "
                + "\n 1- X hamburguer de rato "//demora 20 minutos
                + "\n 2- X filé de grilo "//demora 20 minutos
                + "\n 3- X queijo de cobra "//demora 10 minutos
                + "\n 4- X lonbinho de elefante "//demora 40 minutos
                + "\n 5- X vegetariano (a melhor opção ) "//demora 10 minutos
                + "\n 6- sopa de minhoca");//demora 1 hora
                p[i]=s.nextInt();
            }

            merge(p,aux, 0,p.length-1);
            System.out.println(Arrays.toString(p));
        }


        private static void merge(int[] p, int[] aux, int inicio, int fim) {
            if (inicio<fim) {
             int meio=inicio+fim/2;
              merge(p,aux,inicio,meio);
              merge(p,aux,meio+1,fim);
              intercalar(p,aux,inicio,meio,fim);
            }

        }

        private static void intercalar(int[] p, int[] aux, int inicio, int meio, int fim) {
            for(int i=inicio;i<=fim;i++) 
                aux[i]=p[i];
                int k=inicio;
                int j=meio+1;


            for(int i=inicio;i<=fim;i++) {
                if(k>meio) {
                    p[i]=aux[j++];
                }
                if(j>fim){
                    p[i]=aux[k++];
                }
                if(p[i]<aux[j]){
                    p[i]=aux[i++];
                }
                else {
                    p[i]=aux[j++];
                }
            }
        }

}

Here, compiled normally. I hope I have helped!

    
22.11.2017 / 01:33