JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 ArrayList的問題
grimmu85155





發文: 19
積分: 0
於 2011-11-27 00:36 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
public class test2 {
  @SuppressWarnings(value={"unchecked"})
    public static void main(String[] args) {
        System.out.println("歡迎光臨光復餐廳,本餐廳已開始營業");
        System.out.println("今天天氣:陽光普照");
 
        ArrayList<Customer> customerList = new ArrayList<Customer>();
    ArrayList pricea = new ArrayList();
    ArrayList priceb = new ArrayList();
    ArrayList passtime = new ArrayList();
    int x = 0;
    int y = 0;
    int m;
    int n;
            
        while (true) 
    {
            String choice = ConsoleIn.readLine();
      String a[] = choice.split("\\s+");
      Scanner scanner = new Scanner(System.in);
 
            if(a[0].equals("new")) 
      {  if(a[1].equals("A"))               
              { x++;
        String type = a[1];
                String mealPrice = a[2];
        int mealTime = 30;
        pricea.add(a[2]);
                Customer customer = new Customer(30, type,Integer.parseInt(mealPrice));
                customerList.add(customer);
        System.out.println("新來的客人坐到了座位上點了"+pricea.get(x-1)+"元"+"的餐點,並開始用餐");
        } 
        if(a[1].equals("B"))               
              { y++;
        String type = a[1];
                String mealPrice = a[2];
        int mealTime = 40;
        priceb.add(a[2]);
                Customer customer = new Customer(40, type,Integer.parseInt(mealPrice));
                customerList.add(customer);
        System.out.println("新來的客人坐到了座位上點了"+priceb.get(y-1)+"元"+"的餐點,並開始用餐");
              }
            }
      if(a[0].equals("status"))
      {  for(m=1;m<=x;m++)
        {
          System.out.println("一位點"+"\t"+pricea.get(m-1)+"元"+"\t"+"的A類型客人已用餐");
        }
        for(n=1;n<=y;n++)
        {
          System.out.println("一位點"+"\t"+priceb.get(n-1)+"元"+"\t"+"的B類型客人已用餐");
        }
      
        System.out.println(passtime.get(0));
      
      }
      else if (a[0].equals("pass")) 
      {  String timePassed = a[1];
        System.out.println("經過了"+timePassed+"分鐘");
        double e = Double.parseDouble(timePassed);
                passtime.add(e);
        double k = passtime.get(0);
        for (int i=0;i<x+y;i++) 
        {  
          Customer c=customerList.get(i);
                    double mealTimeLeft=c.getMealTime(e);
                    System.out.println("點"+c.mealPrice+"元的客人"+"用餐時間還剩下"+mealTimeLeft+"分鐘");
                }
        
                System.out.println("-----------------------------------------------------------------------------");
            }
      else if (a[0].equals("exit")) 
      {
                break;
            }
            
        }
 
    }
}

請問為何compile時會出錯
他寫
test2.java:65 : error : incompatible types
double k = passtime.get(0);
required: double
found: Object

我宣告一個陣列passtime來儲存經過的時間
然後宣告一個k來讀此陣列
為何不能??


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
712 ArrayList的問題 grimmu85155 2753 2011-11-27 00:36
562 Re:ArrayList的問題 jimwayne 386 2011-11-27 11:51
476 Re:ArrayList的問題 grimmu85155 8 2011-11-27 13:44
463 Re:ArrayList的問題 alien 66 2011-11-28 10:47
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8