所以我要做的是使用我的ScannerTester类来使用Scanner来读取我的半径,名字和姓氏,然后使用我的JOptionPaneTester类来使用JOptionPane来读取radius,first和last name。我的老师曾经在课堂上讲过这个,但是,我在使JOptionPane正常工作时遇到了一些麻烦。在尝试输入区域的双值时,我不断收到错误。我得到的错误是java.lang.String无法转换为java.lang.Double。但是,当我只输入字符串时它确实有效,但它让我打开了两个不同的String [] args文件。对不起,我还是Java的新手,而且这门课程很快,所以很难跟上这个以及我所有的其他课程。以下是这两个类的代码:
import java.io.*;
import java.util.*;
public class ScannerTester extends JOptionPaneTester
{
public static void main(String [] args)
{
Scanner ScannerTester = new Scanner(System.in);
double area, answer, radius;
String first, last;
System.out.print("What is the area? ");
area = ScannerTester.nextDouble();
radius = (area) / (Math.PI);
answer = Math.sqrt(radius);
System.out.println("Radius of your circle is " + answer);
System.out.println("What is your first name? ");
first = ScannerTester.next();
System.out.println("What is your last name? ");
last = ScannerTester.next();
System.out.println("Your full name is " + first + " " + last);
}
}
import javax.swing.JOptionPane;
public class JOptionPaneTester
{
public static void main (String [] args)
{
Double area, answer, radius;
String first, last, area1;
area = JOptionPane.showInputDialog("What is the area? ");
first = JOptionPane.showInputDialog("What is your first name? ");
last = JOptionPane.showInputDialog("What is your last name? ");
double area = Double.parseDouble(area1);
JOptionPane.showMessaheDialog( null, "What is the area? " );
JOptionPane.showMessageDialog( null, "What is your first name? ");
JOptionPane.showMessageDialog( null, "What is your last name? ");
System.exit (0);
}
}