aspose file tools*
The moose likes Beginning Java and the fly likes Errors while compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Errors while compiling" Watch "Errors while compiling" New topic
Author

Errors while compiling

Andy Rayburn
Greenhorn

Joined: Aug 29, 2006
Posts: 6
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

Joined: Oct 02, 2003
Posts: 10916
    
  12

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 ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143
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).


Stephen Foy - Microsoft Application Development Consultant
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Errors while compiling
 
Similar Threads
two simple troubles.
Ton of problems
Class Help!
my last question for this program.
Error while running program