Estoy construyendo un programa de pedidos para Java para una clase en la escuela y obtengo cantidad La entrada no se puede resolver en un error de variable También obtengo el error

el método showInputDialog(Component, Object, Object) en el tipo JOptionPane no es aplicable para los argumentos (String, int, int)

Cualquier ayuda para resolver los 2 errores será muy apreciada.

/**
 * Course:   IT110 - Introduction to Programming
 * Filename: KagesKreationsPhase1.java
 * Created:  04/09/10 by Dr. Debby Telfer
 * Modified: 11/26/13 by Dr. Bary W Pollack
 * 
 * Purpose:  Created a simple online ordering system
 *           for Pizzas-R-Us customers
 */

import javax.swing.JOptionPane;
import java.io.*;
import java.util.Scanner;
/**
 * @author bary
 */
public class KagesKreations {

    /**
     * @param args
     */
    public static void main(String[] args) {

        // declare variables
        String openingMsg, nameInputMsg, customerName, nameOutputMsg,   getReturning, getColor, getQuantity,
               returnInputMsg, customerReturn, returnOutputMsg, quantityMsg, quantityOutputMsg, totalOutputMsg,
               colorChoiceMsg, colorChoice, colorChoiceOutputMsg, greetingOutputMsg, outputMsg, quantityInput, getname;

        int number = 0;
        double cost = 10.00;
        double taxRate = 1.07;
        double total;


        try {

            // display opening message
            openingMsg = "*** Welcome to Kage's Kreations Online Ordering System ***\n"
                   + "                     Lets Pick A Kustiom Kreation!";
            JOptionPane.showMessageDialog(null, openingMsg);

            // get required input using dialogs
            customerName   = getName();
            customerReturn = getReturning();
            colorChoice    = getColor();
            quantityInput  = getQuantity();
            number = Integer.parseInt(quantityInput);

            KagesKreations.totalCost(number, cost, taxRate);

            total = totalCost(number, cost, taxRate);

            writeOrderFile(customerName, customerReturn, colorChoice,quantityInput, total);
            confirmation();

        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
            System.exit(1);
        }

    } // end main()
    public static String getStringInput(String prompt) throws Exception {
        String value;
        int i = 0;
        do {

            value = JOptionPane.showInputDialog(prompt);i++;

            if (value == null) {
                throw new Exception("Cancle was pressed. Closeing the program.");

            }
        } while (value.equals("") && i < 3); 
           if (value.equals("")) {
               throw new Exception("No input vale was entered after three attempts.");

           }
            return value;
    }


    public static int getQuantity(int lowValue, int highValue) throws Exception {
        // quantity must be between 1-99
        int quantity;
        int counter = 0;
        int quantityInput;

        do {
            quantityInput = Integer.parseInt(JOptionPane.showInputDialog("How many bracelets would you like to order? (1-99)", 1, 99));
            counter = counter + 1;
            } while (quantityInput < lowValue || quantityInput > highValue && counter < 3);
        if (quantityInput < lowValue || quantityInput > highValue) {
            throw new Exception("Invalid responce please enter a number between 1 and 99");

        }


        quantity = quantityInput;
        return quantity;
    }

    public static String getColor() throws Exception {
    String color;
    int counter = 0;
    do {
        color = JOptionPane.showInputDialog("Please choose Brown or Black for the color of your bracelet");
        counter = counter + 1;
        } while (!color.equals("Brown") && !color.equals("Black") && counter < 3);

        if (!color.equals("Brown") && !color.equals("Black")) {
            throw new Exception("Invalid responce please enter Brown or Black.");
            }
        return color;
    }

    public static String getReturning() throws Exception {
        String returning;
        int counter = 0;
        do {
            returning = JOptionPane.showInputDialog("Are you a returning customer? (Yes or No)");
            counter = counter +1;

            } while (!returning.equals("Yes") && !returning.equals("No") && counter < 3 );

        if (!returning.equals("Yes") && !returning.equals("No")) {
            throw new Exception("Invalid responce please enter Yes or No.");
            }

        return returning;
    }

    public static String getName() throws Exception {
        String name;
        int counter = 0;

        do {
            name = JOptionPane.showInputDialog("Please Enter your name.");
            counter = counter + 1;
        } while (counter < 3);
    return name;

    }

    public static double totalCost(int number, double cost, double taxRate){
        double total = 0;
        total = (number * cost) * taxRate;

        return total;
    }

    public static void writeOrderFile(String name, String returning, String color, String quantity, double total) throws Exception {
        File order = new File("order.tx");
        PrintWriter pw = new PrintWriter(order);
        pw.println(name);
        pw.println(returning);
        pw.println(color);
        pw.println(quantity);
        pw.println(total);
        pw.close();
    }

    public static void confirmation() throws Exception{
        String nameOutputMsg, customerName, returnOutputMsg, customerReturn, colorChoiceOutputMsg, colorChoice, quantityOutputMsg, quantityInput,
               totalOutputMsg, total, greetingOutputMsg, outputMsg;

        FileReader fr = new FileReader("order.txt");
        BufferedReader bf = new BufferedReader(fr);
        customerName = bf.readLine();
        customerReturn = bf.readLine();
        colorChoice = bf.readLine();
        quantityInput = bf.readLine();
        total = bf.readLine();

        fr.close();
        // build output strings
                    nameOutputMsg     = "Welcome " + customerName + ".\n\n";
                    returnOutputMsg   = "Your return customer status is " + customerReturn + ".\n";
                    colorChoiceOutputMsg = "You have chosen " + colorChoice + " as the color for your braclet.\n";
                    quantityOutputMsg = "You have ordered " + quantityInput + " bracelets.\n";
                    totalOutputMsg = "Your total cost is $" + total + ".\n";
                    greetingOutputMsg = "Thank you for visiting Kage's Kreations!" + "\n\n"
                                  + "Your order should ships in 24 to 48 hours.\n";


                    // create and display output string
                    outputMsg = nameOutputMsg + returnOutputMsg + colorChoiceOutputMsg + quantityOutputMsg + totalOutputMsg + greetingOutputMsg;
                    JOptionPane.showMessageDialog(null, outputMsg);

    }

} // end class KagesKreationsPhase1
-3
Rick K 26 ene. 2016 a las 07:15

2 respuestas

La mejor respuesta

El segundo problema es que JOptionPane simplemente no proporciona ningún método que coincida con los argumentos que intenta pasar en su getQuantity - método:

quantityInput = Integer.parseInt(JOptionPane.showInputDialog("How many bracelets would you like to order? (1-99)", 1, 99));

Tienes que elegir uno de los métodos existentes.

0
Hulk 26 ene. 2016 a las 06:25

Debes declarar una variable antes de usarla. Puede declarar la variable dentro de getQuantity () o en el nivel de clase (lea mucho sobre las variables locales y de clase). puede declararlo como la forma en que declaró la cantidad y las variables de contador.

  public static int getQuantity(int lowValue, int highValue) throws Exception {
        // quantity must be between 1-99
        int quantity;
        int counter = 0;
        int quantityInput = 0;
    ...
    }

En su código, no puedo encontrar un lugar donde esté usando showInputDialog () con los parámetros String, int, int. Comparte el código completo que estás intentando.

0
Hasanthi 26 ene. 2016 a las 05:31