JOptionPane - 输入对话框程序 [英] JOptionPane - input dialog box program

查看:121
本文介绍了JOptionPane - 输入对话框程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个程序,使用输入对话框读取三个测试标记,每个测试标记100个。程序丢弃最低标记,并在消息对话框中显示两个较高标记的平均值。

Write a program that uses input dialog boxes to read three test marks, each out of 100. The program discards your lowest mark and shows the average of the two higher marks in a message dialog box.

这是我有多远,我不知道从这里做什么,任何帮助将不胜感激:

This is how far i got and i dont know where to do from here, any help would be appreciated:

import javax.swing.JOptionPane; 

public class Average {

    public static void main (String [] args){

        String test1, test2, test3, avg;

        test1= JOptionPane.showInputDialog("Please input mark for test 1: ");

        test2= JOptionPane.showInputDialog("Please input mark for test 2: ");

        test3= JOptionPane.showInputDialog("Please input mark for test 3: ");

    }

}


推荐答案

import java.util.SortedSet;
import java.util.TreeSet;

import javax.swing.JOptionPane;
import javax.swing.JFrame;

public class Average {

    public static void main(String [] args) {

        String test1= JOptionPane.showInputDialog("Please input mark for test 1: ");

        String test2= JOptionPane.showInputDialog("Please input mark for test 2: ");

        String test3= JOptionPane.showInputDialog("Please input mark for test 3: ");

        int int1 = Integer.parseInt(test1);
        int int2 = Integer.parseInt(test2);
        int int3 = Integer.parseInt(test3);

        SortedSet<Integer> set = new TreeSet<>();
        set.add(int1);
        set.add(int2);
        set.add(int3);

        Integer [] intArray = set.toArray(new Integer[3]);
        JFrame frame = new JFrame();
        JOptionPane.showInternalMessageDialog(frame.getContentPane(), String.format("Result %f", (intArray[1] + intArray[2]) / 2.0));

    }

}

这篇关于JOptionPane - 输入对话框程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆