A
A
Alexander Pichuzhkin2021-02-11 19:25:32
Java
Alexander Pichuzhkin, 2021-02-11 19:25:32

Why does it return default?

import java.util.Scanner;
public class TestConditions {

  public static void main(String[] args) {
    Conditions cond = new Conditions();
    try (Scanner scanner = new Scanner(System.in)) {
      System.out.println("Введите первое число:");
      cond.setFirstChange(scanner.nextInt());
      System.out.println("Введите второе число:");
      cond.setSecondChange(scanner.nextInt());
      System.out.println("Введите номер операции: 1.Умножение 2.Деление 3.Сложение");
      cond.setThirdChange(scanner.nextInt());
      cond.operation(cond.getFirstChange(), cond.getSecondChange(), cond.getThirdChange());
    }
  }
}


public class Conditions {
      private int firstChange;
    private int secondChange;
    private int thirdChange;
  
  
    public void setFirstChange(int a){
      a = firstChange;
    }
    public void setSecondChange(int b){
      b = secondChange;
    }	
    public void setThirdChange(int c){
      c = thirdChange;
    }
    
    public int getFirstChange(){
      return firstChange;
    }
    public int getSecondChange(){
      return secondChange;
    }	
    public int getThirdChange(){
      return thirdChange;
    }
      public void operation(int x, int y, int z) {
        switch(z) {
        case 1:
          int res = x*y;
          System.out.println(res);
          break;
        case 2:
          int res1 = x/y;
          System.out.println(res1);
          break;
        case 3:
          int res2 = x+y;
          System.out.println(res2);
          break;
        default:
          System.out.println("Операция не определена");
        }
        
      }
      
}


Returns "Operation not defined". I can't figure out what's wrong?
PS If the question is very stupid, then I apologize in advance, I'm just starting to learn Java.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BorLaze, 2021-02-11
@Arome

1. The text must be formatted.
2. In the setters of the Conditions class, you must assign the value of the parameter to the fields, and not vice versa.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question