Why do I get this error in this java problem? [duplicate]

0

I do not understand, the exercise gives me 4 errors. The statement of the exercise is as follows:

In a class called Coins, the following members are present:
to. Two private variables of type called chain country and currency, the value of the variables must be typed from the keyboard. The code to request that value must write it to the class of the Main method.
b. Create a custom constructor with two parameters of type String that accepts the parameters corresponding to the variables of the class and that displays a message. For example "The currency of legal tender in El Salvador is the dollar", in this message you must concatenate the variables that you will receive in the parameter. Implement the class.

class MonedaPais {

public static void main(String[] args) {
    Scanner ob = new Scanner(System.in);

    System.out.println("Escribe el país: ");
    String pa = ob.nextLine();

    System.out.println("Escribe la moneda: ");
    String mon = ob.nextLine();

    Moneda moneda = new Moneda(pa, mon);

}

}

class MonedaPais10 {
private String pais, moneda;

public static void main(String pais, String moneda) {
    this.pais = pais;
    this.moneda = moneda;

    System.out.println("La moneda de curso legal de " + pais + " es el " + moneda);
} 

The errors that come out are:

  

MonedaPais10.java:14: error: can not find symbol           Currency currency = new Currency (pa, mon);           ^ symbol: class Currency location: class Currency Currency Pais10.java:14: error: can not find symbol           Currency currency = new Currency (pa, mon);                               ^ symbol: class Currency location: class CurrencyPais CurrencyPais10.java:24: error: non-static variable this   can not be referenced from a static context           this.pais = country;           ^ CurrencyPais10.java:25: error: non-static variable this can not be referenced from a static context           this.moneda = currency;           ^ 4 errors

    
asked by Marcos Pérez 11.11.2017 в 20:53
source

1 answer

1

I think you're a bit confused with what a void main is and what a constructor is, in the currency classPais10 you have a main as in the currency class Country,

The second should be like this

class MonedaPais10 {
private String pais, moneda;

public MoneaPais10(String pais, String moneda) {
    this.pais = pais;
    this.moneda = moneda;

    System.out.println("La moneda de curso legal de " + pais + " es el " + moneda);
} 

to be able to initialize an object with parameters since that is your constructor

Second, you use the Currency class in your main and you did not put anything on a currency class.

    
answered by 11.11.2017 в 21:29