This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2015/12/20

int[] cannot be converted to int

divinity divinity

2015/12/20

#
hi all I am doing an assignment for school. it is creating a java point of sales system for a franchise company. I have to implement methods and arrays. arrays is not my strong point in programming. another problem is when i am calling the methods i am getting an error. when i implementing the arrarys, i am getting this annoying errors int cannot be converted to int double cannot be converted to double is there anyway that can be fixed
Super_Hippo Super_Hippo

2015/12/20

#
1
//int[] is an array of ints (only code tag because '[]' can't be displayed without)
int is just one int. Same with double. So you can't convert one to the other. Where are you getting this error? If you show the code, we can help you to fix it.
divinity divinity

2015/12/21

#
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
public static double calGrandTotal(double extendedprice[])
    {
       int  i;
        double sum = 0;
         
         
        for(i = 1; i<=5; i++)
        {
            sum += extendedprice[i];
                    
        }
         
        return sum;
    }
     public static double calDiscountAmount(double calGrandTotal, double discountamt)
    {
         double  total =0;
          
         total = (calGrandTotal * discountamt);
           
         return discountamt;
    }
     public static double calFinalPrice(double calGrandTotal,double discountamt)
     {
         double finalprice = 0;
          
         finalprice = (calGrandTotal - discountamt);
          
         
         return finalprice;
    }
the codes above is the method which i am trying to call in the main
 
 int item_num[] = new int[item_num];int[]cannot be converted to int
        double item_descript[]= new double[item_descript];-here is where I am getting the double[] cannot be converted to double
        double unit_prices[]= new double[unit_prices];
        double quantities[] = new double[quantities];
        double extendedprices[]= new double[extendedprice];
         
         
                 
        System.out.println("Hello can you tell me your name please");
        String firstname = userinput.next();
         
        System.out.println("Hello can you tell me your last name please");
        String lastname = userinput.next();
         
        System.out.println("Hello can you tell me what is the amount of item you want to purchase");
        double amt_of_items = userinput.nextDouble();
         
        System.out.println("Hello what was the discount amount on the bill");
        double disc_amt = userinput.nextDouble();
         
        System.out.println("Hello can you tell me what is the item number");
        item_num[i] = userinput.nextInt();
         
         
         
         
         
         
        calGrandTotal(extendedprice[]);-this is the method i am trying to call in the main and I am getting this error- cannot find symbol
        calDiscountAmount(GrandTotal(extendedprice) discountamt);
danpost danpost

2015/12/21

#
When creating arrays (such as in lines 34 through 38 above), you must give it how many elements it can hold. So, the item_num array should have an element slot for each item_num (the maximum number of different item numbers you will be using). You are, for some unknown reason, placing the name of the array where this int value should go. So, if you had ten different item numbers, then:
1
int[] item_num = new int[10];
would declare and create an array for ten int values.
You need to login to post a reply.