Andy Rayburn

Greenhorn
+ Follow
since Aug 29, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andy Rayburn

Hi

I have a program I am running for a project for my class. The project compiles just fine but when it gets to a certain point it blows up and gives me an error.

The error is

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.String; at Project02.calculate(Project02.java:106)
at Project02.main(Project02.java:79.


Here is my 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 (args.length == 0) {
taxRate = .06;
}
else {
String taxRateAsString = args[0]; // 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 " + Utility.percentFormat(taxRate)); // 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.toUpperCase() == "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(double prices[], ArrayList quantites) {
double total = 0;
for (int i = 0; i < prices.length; i++) { // LIMIT BY SIZE OF THE ARRAY.
double price = prices[i]; // GET THE ITEM'S PRICE.
int quantity = ((Integer)quantites.get(i)).intValue(); // GET CORRESPONDING QUANTITY ORDERED.
double extendedPrice = price * quantity;
total += extendedPrice;
}
return total;
}
}


Please help

Thanks
15 years ago
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
15 years ago
Hi,
I have a Lab problem for a class that I am doing but when I go to compile it I am getting an error that I have no clue what it is. Here is the program

import java.util.*;
public class Lab23A {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(new String("Happy"));
list.add(new String("Sleepy"));
list.add(new String("Sneezy"));
list.add("Doc");
for (int i = 0; i < list.size(); i++) {
System.out.println((String)list.get(1));
}
}
}

The error I get is as followed

Note: Lab23A.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Can someone help please.

Thanks
15 years ago
Hi all,

I was wondering if someone could help. First let me start by saying that this problem is for a class. I have looked through some past posts but I am not sure I am looking for the right thing.

The problem is I need to make a code that will swap the first and last characters in an array. But I have to figure out how to keep it simple so that no matter how big the array gets it will perform the same way. Here is what I have so far.

public class Lab21C {
public static void main(String[] args) {
char[] table = {'a', 'b', 'c', 'd'};

If someone could get me going in the right direction I would really appreciate it.

Thanks
15 years ago
Thank you very much your reply did help.
15 years ago
OK, I am new to Java. I am trying to figur out how to convert a percentage such as 15% to a decimal like .15 and then converting it back. I have done some serching but I think I am looking and asking for the wrong thing.

Thanks
15 years ago