This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Errors while compiling

 
Andy Rayburn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project I am doing for class and I have everything filled the way I think it is supposed to be but I am getting a couple errors that I can not seem to fix. I was wondering if anyone can give me a suggestion. Here is the program.

import java.util.*;
import java.io.*;
import java.text.*;

// This class defines a program to process orders for a fast food restaurant.
// ---- Written by: Jon Huhtala
// --- Modified by: Andy Rayburn
public class Project02 {

// This method begins application processing.

public static void main(String[] args) {

// Variables.

double taxRate; // For holding the tax rate.
String reply; // For holding the user's latest keyboard entry.
ArrayList quantities; // For holding the item quantities for the
// customer order.

// These coordinated arrays hold item names and their prices

String[] items = {"Burgers", "Fries", "Drinks"};
double[] prices = {2.75, 1.50, 1.35};

// If the program did not receive a command line parameter, set the
// tax rate to .06 (meaning 6%). Otherwise, set the tax rate to the
// value of the parameter.

if (taxRate == 0) {
taxRate = .06;
}
else {
String taxRateAsString = " "; // GET PARAMETER VALUE.
taxRate = Double.parseDouble (taxRateAsString); // CONVERT FROM String TO double.
}

// Loop to process one customer order.

do {

// Display item names and prices.

System.out.println("");
System.out.println("--------- ITEMS AND PRICES ---------");
System.out.println("");

// THIS LOOP SHOULD DISPLAY ITEM NAMES AND PRICES IN A FORMAT THAT
// MATCHES THE SAMPLE OUTPUT SHOWN BELOW.

for (int i = 0; i < items.length; i++) { // LIMIT BY SIZE OF items ARRAY.
System.out.println(" " + items[i] + "..." + Utility.moneyFormat(taxRate));
}

// Get order data.

System.out.println("");
System.out.println("------------ YOUR ORDER ------------");
System.out.println("");
quantities = new ArrayList();

// THIS LOOP SHOULD PROMPT FOR AND READ THE NUMBER OF EACH ITEM THE
// CUSTOMER WANTS TO BUY. IT SHOULD MATCH THE FORMAT OF THE SAMPLE
// OUTPUT SHOWN BELOW.

for (int i = 0; i < items.length; i++) { // LIMIT BY SIZE OF items ARRAY.
System.out.print(" Number of " + items[i] + ": ");
reply = Utility.readString();
quantities.add (items); // ADD TO THE quantities ArrayList.
}

// Calculate and display "Payment Due" information.

System.out.println("");
System.out.println("----------- PAYMENT DUE ------------");
System.out.println("");
double subtotal = calculate(prices, quantities);
System.out.println(" Subtotal: " + Utility.moneyFormat(subtotal));
double tax = subtotal * taxRate;
System.out.println(" Tax: " + Utility.moneyFormat(tax) +
" at " + (" taxrate * 100" + " % ")); // SHOW taxRate AS FORMATTED PERCENTAGE.
double totalDue = subtotal + tax;
System.out.println(" TOTAL: " + Utility.moneyFormat(totalDue));

// Ask the user if they want to process another order. If they reply with
// a String whose value is "YES", repeat this loop.

System.out.println("");
System.out.println("-------------- AGAIN? --------------");
System.out.println("");
System.out.print(" Enter YES to do another order: ");
reply = Utility.readString();
} while ( reply == "yes"); // ACCEPT "YES" IN ANY CASE (LIKE "yes") TO CONTINUE.
}

// This method can be called to calculate the non-taxable amount due for
// an order. It receives the array of prices and ArrayList of corresponding
// quantities as parameters.

public static double calculate(int order, double amount) {
double total = 0;
for (int i = 0; i < prices.length; i++) { // LIMIT BY SIZE OF THE ARRAY.
double price = amount; // GET THE ITEM'S PRICE.
int quantity = order; // GET CORRESPONDING QUANTITY ORDERED.
double extendedPrice = price * quantity;
total += extendedPrice;
}
return total;
}
}


The errors I am getting are as follow.

Project02.java:79: calculate(int,double in Project02 cannot be applied to (double[],java.util.arraylist)
double subtotal = calculate(prices, quatities):

Project02.java:104: cannot find symbol
symbol : varible prices
location: class Project02
for (int i=0: i < prices.length; i++) {

Please help

thanks
 
fred rosenberger
lowercase baba
Bartender
Posts: 12146
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Project02.java:79: calculate(int,double) in Project02 cannot be applied to (double[],java.util.arraylist) double subtotal = calculate(prices, quatities):


your calculate() method is expecting an int and a double. you are passing it an int and an arraylist.

the other error stems from the fact that your calculate method doesn't know what "prices" is. I'm not sure if you want to pass in the array "prices", if you want to pass in the size of hte array, or pass in the array itself...
[ November 09, 2006: Message edited by: fred rosenberger ]
[ November 09, 2006: Message edited by: fred rosenberger ]
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all you are referring to prices.length the prices array is in the main method and cannot be accessed outside the main method so you have to give the prices array class scope.



Also on line 80



The method calculate is looking for an int parameter and a double parameter, not calculate(double, arraylist).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic