Вопрос по java – Попытка создания экземпляров объектов внутри цикла for и сбой

-1

По сути, я пытаюсь создать новый класс, если переменная продолжения равна & quot; Y & quot ;. У меня проблема в том,

DigitalMain.java:18: not a statement
    DigitalPhoto[] class = new DigitalPhoto[9];

после компиляции. Я посмотрел на ArrayLists, но я не совсем уверен, будут ли они создавать экземпляры классов так же, как я пытаюсь достичь. В идеальной ситуации у меня были бы объекты с именем «класс» + i и различными значениями для каждого объекта через их встроенные методы set.

// Import classes for class
import java.util.Arrays;
import java.util.List;
import javax.swing.*;
import java.awt.event.*;
import java.text.DecimalFormat;

public class DigitalMain
{
  public static void main(String args[])
  {
    String cont = "Y";
    String heightString,widthString,width,bitpsString;
    double bitps,x,y,totesPrice,totesSize,totesSpeed;
    DecimalFormat wholeDigits = new DecimalFormat("0");
    DecimalFormat dec = new DecimalFormat("0.00");

    DigitalPhoto[] picc = new DigitalPhoto[20];
    for(int i=0; cont.equals("Y") ; i++)
    {
    picc[i] = new DigitalPhoto();
    heightString = JOptionPane.showInputDialog("Please enter height");
    picc[i].setHeight = Double.parseDouble(heightString);
    heightString = JOptionPane.showInputDialog("Please enter width");
    picc[i].setWidth = Double.parseDouble(widthString);
    continueQuestion = JOptionPane.showInputDialog("Height: " + picc[i].getHeight + "\n Width: " + picc[i].getWidth + "\n Resolution: " + picc[i].getResolution + "\n Compression Ratio: " + picc[i].getCompression + "\n Required Storage: " + picc[i].calcStorage() + "\n Price of Scanned Photo: " + picc[i].getCost() + "Please enter 'Y' to try again or anything but 'Y' to accept values.");
    };


    do
    {
    bitpsString = JOptionPane.showInputDialog("Please enter your internet connection speed. Must be an integer between 1 and 99999999");
    bitps = Double.parseDouble(bitpsString);
    } while (bitps > 0 && bitps < 99999999);
    picc0.setSpeed(bitps);

    for(y = 0; y<picc.length; y++) {
      totesPrice += picc+y.getCost();
      totesSize += picc+y.calcStorage();
      totesSpeed = picc0.getSpeed();
    }

    double seconds = transferTime(totesSize, totesSpeed);
    double minutes = seconds / 60;
    double realsec = seconds % 60;

    JOptionPane.showMessageDialog(null, "You will be paying: " + totesPrice + "\nRequired Storage is: " + totesSize + "Required time for transfer is: " + wholeDigits.format(minutes) + " minutes, and " + wholeDigits.format(realsec) + " seconds.");

  }

  public static double transferTime(double totalStorage, double netSpeed) {
    double bits, seconds;
    bits = (totalStorage * 8);
    seconds = (bits / netSpeed);
    return seconds;
    };
}

Ваш Ответ

4   ответа
0

 You cannot use any of the following(in list of keywords) as identifiers in your
 programs.The keywords const and goto are reserved, even though they are not 
 currently used. true, false, and null might seem like keywords, but they 
 are actually literals;      you cannot use them as identifiers in your programs.

for(int i=0; cont.equals("Y") ; i++)
 {
   class[i] = new DigitalPhoto();
   heightString = JOptionPane.showInputDialog('Please enter height');
   class[i].setHeight = double.parseDouble(heightString);
   heightString = JOptionPane.showInputDialog('Please enter width');
   class[i].setWidth = double.parseDouble(widthtString);
   continueQuestion = JOptionPane.showInputDialog('Height: ' + 
   class[i].getHeight + '\n\lWidth: ' + class[i].getWidth + '\n\l Resolution: ' +
   class[i].getResolution + '\n\lCompression Ratio: ' +  class[i].getCompression +
  '\n\lRequired Storage: ' + class[i].calcStorage() + '\n\lPrice of Scanned Photo: ' + 
    class[i].getCost() + 'Please enter "Y" to 
   try again or anything but "Y" to accept values.')
} while {continue.equalsIgnoreCase(Y)};

for-while

1

classArrayLists

List<DigitalPhoto> photoes = new ArrayList<DigitalPhoto>(); 
do
    {
    DigitalPhoto photo = new DigitalPhoto();
    heightString = JOptionPane.showInputDialog('Please enter height');
    photo .setHeight = double.parseDouble(heightString);
    heightString = JOptionPane.showInputDialog('Please enter width');
    photo .setWidth = double.parseDouble(widthtString);
    photos.add(photo)
    continueQuestion = JOptionPane.showInputDialog('Height: ' + class[i].getHeight + '\n\lWidth: ' + class[i].getWidth + '\n\l Resolution: ' + class[i].getResolution + '\n\lCompression Ratio: ' + class[i].getCompression + '\n\lRequired Storage: ' + class[i].calcStorage() + '\n\lPrice of Scanned Photo: ' + class[i].getCost() + 'Please enter "Y" to try again or anything but "Y" to accept values.')
    } while {cont.equals("Y")};
1

Error: User Rate Limit Exceeded

for(...)
{
...
}while();

Error: User Rate Limit Exceededfor-whileError: User Rate Limit Exceeded

Error: User Rate Limit ExceededforError: User Rate Limit Exceeded
Error: User Rate Limit Exceededfor-whileError: User Rate Limit Exceeded

continueQuestion = JOptionPane.showInputDialog('Height: ' + class[i].getHeight + '\n\lWidth: ' + class[i].getWidth + '\n\l Resolution: ' + class[i].getResolution + '\n\lCompression Ratio: ' + class[i].getCompression + '\n\lRequired Storage: ' + class[i].calcStorage() + '\n\lPrice of Scanned Photo: ' + class[i].getCost() + 'Please enter "Y" to try again or anything but "Y" to accept values.') // you miss the ;     
3

classError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

for(int i=0; cont.equals("Y") ; i++)
{
    ...
} while {continue.equalsIgnoreCase(Y)};

Error: User Rate Limit ExceededforError: User Rate Limit ExceededwhileError: User Rate Limit Exceededdo/whileError: User Rate Limit Exceeded

Error: User Rate Limit ExceededactuallyError: User Rate Limit ExceededforError: User Rate Limit ExceededwhileError: User Rate Limit Exceeded

Error: User Rate Limit ExceededcontainingError: User Rate Limit Exceeded

Error: User Rate Limit Exceededdo/while:

do
{
    ...
} while {bitps > 0 && bitps < 99999999};

Error: User Rate Limit ExceededwhileError: User Rate Limit ExceededroundError: User Rate Limit Exceeded

do
{
    ...
} while (bitps > 0 && bitps < 99999999);

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded user1251814

Похожие вопросы