1 // This program reads in an item's cost and some coupons' information,
2 // and then determines which is the best coupon to use and the amount
3 // to pay.
4
5 import java.util.*;
6
7
8 public class Redeem {
9
10 public static void main(String[] args) {
11 Scanner sc = new Scanner(System.in);
12 double price = sc.nextDouble();
13 int size = sc.nextInt();
14 int i=0;
15 double amtPay = price;
16 double negativeAmt= -99999.99;
17
18 ArrayList<Coupon>coupons = new ArrayList<Coupon>(size);
19
20 for(i=0; i<size; i++) {
21 Coupon newCoupon = new Coupon(sc.next(), sc.nextDouble());
22 coupons.add(i, newCoupon);
23 sc.nextLine();
24 }
25
26 for(i=0; i<size; i++) {
27 double temp = (coupons.get(i)).payment(price);
28 if (temp < 0) {
29 if (temp > negativeAmt) {
30 negativeAmt = temp;
31 Coupon bestCoupon = new Coupon(coupons.get(i));
32 }
33 amtPay = 0.00;
34 }
35 else {
36 if (amtPay != 0) {
37 if (temp < amtPay) {
38 amtPay = temp;
39 }
40 Coupon bestCoupon = new Coupon(coupons.get(i));
41 }
42 }
43 }
44 System.out.println("Best choice: " + bestCoupon);
45 System.out.printf("You need to pay $%.2f\n", amtPay);
46 }
47 }
내가 점점 계속 오류가이가 초기화되었을 때 개체에 대한 기호 오류를 발견하고 정의 할 수 없습니다
Redeem.java:44: error: cannot find symbol
System.out.println("Best choice: " + bestCoupon);
^
symbol: variable bestCoupon
location: class Redeem
1 error
왜 그것이 쿠폰 클래스의 객체라고 볼 수 없습니다입니까? 나는 (println 메소드는 문자열을 감지합니다 그것은 있도록 toString 메소드와 함께)이 전에 내 쿠폰 클래스를 컴파일하고 여전히 만이 알려져이 문제 :(helppp 이 if
의 범위에을 선언
쿠폰 bestCoupon 쿠폰의 범위'bestCoupon' 내부 접근 블록이 선언되었습니다. – makata