Java 어디가 잘못됐는지 못찾겠습니다.. 도와주세요.

조회수 434회
public class Duplicate{

  public static void main(String[] args){
    double dishes = 0.0;
    int studentdiscount = 50;
    int workerdiscount = 25;
    int guestdiscount = 0;
    int discountreal = 0;
    double discountprice = 0.0;
    int isxmas = 0;

    dishes = Terminal.askFloat("how much is the dishes? ");
    isxmas = Terminal.askInt("is today xmas? (y: 1, n: 0)");

    discountreal = isxmas * studentdiscount; //instance1
    discountprice = dishes * (1 - discountreal/100.0); //instance1
    System.out.printf("\nit costs: %.2f dollar for student.\n", discountprice);

    discountreal = isxmas * workerdiscount; //instance2
    discountprice = dishes * (1 - discountreal/100.0); //instance2
    System.out.printf("\nit costs: %.2f dollar for workers.\n", discountprice);

    discountreal = isxmas * guestdiscount; //instance3
    discountprice = dishes * (1 - discountreal/100.0); //instance3
    System.out.printf("\nit costs: %.2f it costs: %.2f dollar for guests.\n", discountprice);

  }
}

위의 코드에서 반복되는 instance 부분들을 메소드를 사용해 간단하게 해야하는게 문제입니다. 아래가 제가 나름대로 해 본 부분인데, 실행하면 자꾸 0 만 나옵니다... 변수선언 위치가 잘못되었는지, 어쨌는지 도대체가 모르겠습니다. 제발 도와주세요..ㅠㅠ

public class Test{

  public static double discountprice(double dishes, int xmas, int studentdiscount){
    return dishes * (1 - (xmas * studentdiscount/100.0));
  }

  public static void main(String[] args){
    double dishes = 0.0;
    int studentdiscount = 50;
    int discountreal = 0;
    double discountprice = 0.0;
    int isxmas = 0;

  dishes = Terminal.askFloat("how much is the dishes? ");
  isxmas = Terminal.askInt("is today xmas? (y: 1, n: 0)");

  System.out.printf("\nit costs: %.2f dollar for student.\n", discountprice);
  System.out.printf("\nit costs: %.2f dollar for workers.\n", discountprice*1.5);
  System.out.printf("\nit costs: %.2f it costs: %.2f dollar for guests.\n", discountprice*2);
  }
}
  • (•́ ✖ •̀)
    알 수 없는 사용자
  • Terminal 클래스 소스도 올려주세요 정영훈 2019.11.22 08:37
  • 그리고 질문상의 코드는 무엇을 하는 코드이며 입력값 무엇을 넣었을때 기대하는 결과값은 무엇인지요? 코드만 덩그리 올리고 안됩니다. 라고 올리면 이것을 보는 입장에서 답답합니다. 정영훈 2019.11.22 08:45
  • 아 네. terminal 클래스 소스는 제가 짠게 아니라, 교수님이 올려주신 걸 썼는데 여러가지가 담겨있어 굉장히 복잡합니다. 요약하자면 일단은 dishes에 음식가격을 입력하고, isxmas는 할인이 되느냐 안되느냐를 결정짓는 값으로 1이나 0을 씁니다. 그런다음 할인가격을 계산하는겁니다. 결과값은 결국 discountprice 입니다. 알 수 없는 사용자 2019.11.22 09:12
  • @정영훈 와. 정말 감사합니다. 덕분에 해결했습니다. 가르쳐 주셔서 정말 감사합니다! 알 수 없는 사용자 2019.11.22 20:14

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)