为什么我的代码说JOptionPane和Interger是不可理解的变量



我有一项任务要制作一个程序,该程序使用二维数组来显示根据年龄和孩子在日托中心的天数,让孩子留在日托中心的费用。我一直收到一条错误消息,上面写着"找不到符号。变量:JOptionPane"。这将显示包括该代码在内的所有代码。它也显示相同的错误,但这次显示的是"variable:Interger"。我错过了什么?

import java.util.Scanner;
public class DayCare
{
public static void main(String args[]) 
{
// Declare two-dimensional array here.
double pay[][] = {{30, 60, 88, 115, 140},
{26, 52, 70, 96, 120},
{24, 46, 67, 89, 110},
{22, 40, 60, 75, 88},
{20, 35, 50, 66,84}};      
// Declare other variables.
int numDays;   
int age;
String numDaysString;
String ageString;
int QUIT = 99;
Scanner input = new Scanner(System.in);
// This is the work done in the getReady() method
// Perform a priming read to get the age of the child.
ageString = JOptionPane.showInputDialog("Enter age of child: ");
age = Interger.parseInt(ageString);
while(age != QUIT)
{  
// This is the work done in the determineRateCharge() method
// Ask the user to enter the number of days
numDaysString = JOptionPane.showInputDialog("Enter number of days: ");
numDays = Interger.parseInt(numDaysString);
// Print the weekly rate
System.out.println(" Pay is $" + pay[age][numDays]);
// Ask the user to enter the next child's age
ageString = JOptionPane.showInputDialog("Enter age of child: ");
age = Interger.parseInt(ageString);
}
// This is the work done in the finish() method
System.out.println("End of program");
System.exit(0);
} // End of main() method.
} // End of DayCare class.

如果您只是在学习如何处理二维数组,请尝试一下,这样您就不必处理麻烦的循环和控制台。

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class Junk {
public static void main(String [] args) {
double pay[][] = {{30, 60, 88, 115, 140},
{26, 52, 70, 96, 120},
{24, 46, 67, 89, 110},
{22, 40, 60, 75, 88},
{20, 35, 50, 66,84}};      
final JComboBox<Integer> ageCombo = new JComboBox<Integer>(new Integer[] {0, 1, 2, 3, 4});
final JComboBox<Integer> daysCombo = new JComboBox<Integer>(new Integer[] {1, 2, 3, 4, 5});
final JLabel costLabel = new JLabel();
JDialog dialog = new JDialog();
dialog.setLayout(new GridBagLayout());
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.add(new JLabel("Age of Child:"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0));
dialog.add(ageCombo, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
dialog.add(new JLabel("Number of Days:"), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0));
dialog.add(daysCombo, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
dialog.add(costLabel, new GridBagConstraints(0, 2, 2, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
final String costFmt = " Pay is $%.2f";
ItemListener listener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
int age = (Integer) ageCombo.getSelectedItem();
int days = (Integer) daysCombo.getSelectedItem() - 1;
costLabel.setText(String.format(costFmt, pay[age][days]));
}
}
};
costLabel.setText(String.format(costFmt, pay[0][0]));
ageCombo.addItemListener(listener);
daysCombo.addItemListener(listener);
dialog.setAlwaysOnTop(true);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
} // End of main() method.
}

最新更新