I have to you’ll create an array of 20 values in dollars and cents format ($1.59). Then create four separate methods within the program to complete the listed tasks. The first method should create a total of all of the values listed in the array. The second should search the array, and return a listing of all values that are less than $5.00. The third should return the average of the values in the array. (Use the output from the first method.) Finally, display a list of all values in the array that are greater than the average value.
I keep getting these errors : ----jGRASP exec: javac -g Prices.java
Prices.java:3: missing method body, or declare abstract
public static void main(String[] args);
^
Prices.java:32: operator + cannot be applied to double,double[]
total +=prices;
^
Prices.java:41: operator < cannot be applied to double[],double
if (prices < 5.00);
^
Prices.java:46: incompatible types
found : int
required: boolean
if (i / 20)
^
Prices.java:50: operator > cannot be applied to double[],double
if (prices > average)
^
5 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete. Prices.java
Java
Last Comment
for_yan
8/22/2022 - Mon
for_yan
public static void main(String[] args); <--- should not have semicolon in the end of this line
The rest of the errors after such error - you don;t need to look at - verything is screwed up - recompile again
OHHH ok i get it now I had to add all the prices together using the brackets. Now I run the program and get this:
----jGRASP exec: java Prices
The total of all prices are 288.49999999999994
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20
at Prices.main(Prices.java:38)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Why isn't the values less than $5.00 showing or the average. I created the method for it.
Ok I've got that but how would I go about displaying the average of the prices? Would it be
average =total/20; ?? Prices.java
for_yan
Yes it would be and you do not need to print it in the lloop it is justone onumberJust print itSystem.out.println("Average: " + average);without any loop.Also understand that your for lopp can apply either to one operator - thenyou don't need vbraces, like there:for (i = 0; i < 20;i++)System.out.println("i : " + i);this one opertor will be repeated 20 times with changing iif you have more than one operator repeating or say "if" with operator then you need to put braces arounfd the group which needs to be repaeted.In order not to worry - I recommedn to put braces always - both in this case:for (i = 0; i < 20;i++){ if (prices[i] > average) System.out.println(prices[i] + " are greater than the average value");}and even in this case:for (i = 0; i < 20;i++){System.out.println("i : " + i);}then you'll not have to worry and will not make mistake executing only one operator of te intended groupand it is easier to see the logicSo correct in this way all your loops
Okay so to print the values that are greater than the average value am I supposed to write it like this:?
System.out.println( "is greater than the average value");
It will find it on its own? Prices.java
public static void main(String[] args); <--- should not have semicolon in the end of this line
The rest of the errors after such error - you don;t need to look at - verything is screwed up - recompile again