1:编写一个程序,用map 实现学的成绩单的存储和查询,并且对成绩进行排序存储到treeset中,求最大值,最小值,和平均成绩
2:编写在其中调用外部程序“cmd”,并显示其输入结果
3:编写一个日历程序

解决方案 »

  1.   

    唉~~,没有代码,只有思路:1.Map的话可以采用HashMap<String,Integer>类型,可以使用
    Set<Integer> set = new TreeSet(map.values());
    就可以了,TreeSet会自动排序,不需要人工干预。
    这个问题也是有bug的,TreeSet中不能存放两个相同的值,如果有两个学生的成绩一样就只会存一个!2.代码:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;public class Test {
        public static void main(String[] args) throws IOException {
            Runtime run = Runtime.getRuntime();
            Process process = run.exec("cmd /cdir");
            InputStream is = process.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String str = "";
            while((str=br.readLine())!=null) {
                System.out.println(str);
            }
            br.close();
        }
    }3.做日历比较烦,可以使用Calendar类,自己去看看API吧。
      

  2.   

    我不是呀,我是自学java的买了这本书课后的习题有的不会,所以就请教大家,我不是学软件的我是学网络的。不过还有那么多好心人帮助我很高兴,谢谢大家了。
      

  3.   

    package calendar;import java.awt.*;
    import java.awt.event.*;
    import java.text.DateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import javax.swing.*;
    public class MyCalendar extends JFrame implements MouseListener{ int year, month, day;
    JTextField showDay[];
    JLabel title[];
    Calendar calendar;
    int weekDay;
    Month chargeMonth;
    Year chargeYear;
    String[] week = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
    JPanel leftPanel, rightPanel;

    public MyCalendar(int year, int month, int day) {
    super("Calendar" + "                     "
      + "by unique.wu" + "               "
      + "May you success!"); 
    leftPanel = new JPanel();
    JPanel leftCenter = new JPanel();
    leftCenter.setLayout(new GridLayout(7,7));

    rightPanel = new JPanel();
    this.year = year;
    this.month = month;
    this.day = day;
    chargeYear = new Year(this);
    chargeYear.setYear(year);
    chargeMonth = new Month(this);
    chargeMonth.setMonth(month);

    title = new JLabel[7];
    showDay = new JTextField[42];
    for(int j=0; j<7; j++) {
    title[j] = new JLabel();
    title[j].setText(week[j]);
    title[j].setBorder(BorderFactory.createRaisedBevelBorder());
    leftCenter.add(title[j]);
    }
    title[0].setForeground(Color.red);
    title[6].setForeground(Color.pink);

    for(int i=0; i<42; i++) {
    showDay[i] = new JTextField();
    showDay[i].addMouseListener(this);
    showDay[i].setEditable(false);
    leftCenter.add(showDay[i]);
    }
    calendar = Calendar.getInstance();
    Box box = Box.createHorizontalBox();
    box.add(chargeYear);
    box.add(chargeMonth);
    leftCenter.add(box);
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(leftCenter.add(box), BorderLayout.NORTH);
    leftPanel.add(leftCenter, BorderLayout.CENTER);
    String myString1 = DateFormat.getDateInstance().format(new Date());
    String myString2 = DateFormat.getTimeInstance().format(new Date());
    leftPanel.add(new Label(myString1 + "    " + myString2), BorderLayout.SOUTH);
    leftPanel.validate();
    Container con = getContentPane();
    con.add(leftPanel, BorderLayout.CENTER);
    con.validate();
    setCalendar(year, month);
    addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    });
    setVisible(true);
    setBounds(50, 25, 450, 240);
    validate();
    }
    public void setCalendar(int year, int month) {
    calendar.set(year, month-1, 1);

    weekDay = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    if(month ==1 || month == 2 || month == 3 || month == 5 || month == 7||
    month == 8 || month == 10 ||month == 10|| month == 12) {
    arrangeNumber(weekDay, 31);
    } else if (month ==4 || month ==6 || month == 9 || month ==11) {
    arrangeNumber(weekDay, 30);
    } else if (month ==2) {
    if((year%4 == 0 && year %100 !=0) || (year % 400 == 0)) {
    arrangeNumber(weekDay, 29);
    } else {
    arrangeNumber(weekDay, 28);
    }
    }
    }

    public void arrangeNumber(int weekDay, int monthDays) {
    for(int i = weekDay, n=1; i<weekDay + monthDays; i++) {
    showDay[i].setText(" " + n);
    if (n == day) {
    showDay[i].setForeground(Color.green);
    showDay[i].setFont(new Font("TimesRoman", Font.BOLD, 20));
    } else {
    showDay[i].setFont(new Font("TimesRoman", Font.BOLD, 12));
    showDay[i].setForeground(Color.blue);
    }
    if ((i%7 == 6) && (n != day)) {
    showDay[i].setForeground(Color.pink);
    }
    if((i%7 == 0) && (n != day)){
    showDay[i].setForeground(Color.red);
    }
    n++;
    }
    for (int i=0; i<weekDay; i++) {
    showDay[i].setText(" ");
    }
    for (int i = weekDay + monthDays; i<42;i++) {
    showDay[i].setText(" ");
    }

    }
    public int getYear() {
    return year;
    }
    public void setYear(int y) {
    year = y; }
    public int getMonth() {
    return month;
    }
    public void setMonth(int m) {
    month = m;
    }
    public int getDay() {
    return day;
    }
    public void setDay(int d) {
    day = d;
    }
    public void mousePressed(MouseEvent e) {
    JTextField source = (JTextField)e.getSource();
    try {
    day = Integer.parseInt(source.getText());
    } catch (Exception ee) {
    }
    }

    public void mouseClicked(MouseEvent e) {


    } public void mouseEntered(MouseEvent e) {


    } public void mouseExited(MouseEvent e) {


    }
    public void mouseReleased(MouseEvent e) {


    }
    public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    int y = calendar.get(Calendar.YEAR);
    int m = calendar.get(Calendar.MONTH) + 1;
    int d = calendar.get(Calendar.DAY_OF_MONTH);
    new MyCalendar(y, m , d);
    }
    }
    ---------------------------------------------------
      

  4.   


    package calendar;import java.awt.Color;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JTextField;public class Year extends Box implements ActionListener{

    int year = 0;
    JTextField showYear = null;
    JButton nextYear,lastYear;
    MyCalendar calendar;
    public Year(MyCalendar calendar) {
    super(BoxLayout.X_AXIS);
    showYear = new JTextField(4);
    showYear.setForeground(Color.blue);
    showYear.setFont(new Font("TimesRomn", Font.BOLD, 14));
    this.calendar = calendar;

    year = calendar.getYear();
    nextYear = new JButton(" nextYear");
    lastYear = new JButton(" lastYear");
    add(lastYear);
    add(showYear);
    add(nextYear);
    showYear.addActionListener(this);
    lastYear.addActionListener(this);
    nextYear.addActionListener(this);
    }
    public void setYear(int year) {
    this.year =year;
    showYear.setText(" " + year);
    }
    public int getYear() {
    return year;
    }
    public void actionPerformed(ActionEvent e) {
    if(e.getSource() == lastYear) {
    year = year - 1;
    showYear.setText(" " + year);
    calendar.setYear(year);
    calendar.setCalendar(year, calendar.getMonth());
    } else if (e.getSource() == nextYear) {
    year = year + 1;
    showYear.setText(" " + year);
    calendar.setYear(year);
    calendar.setCalendar(year, calendar.getMonth());
    } else if(e.getSource() == showYear) {
    try {
    year = Integer.parseInt(showYear.getText());
    showYear.setText(" " + year);
    calendar.setYear(year);
    calendar.setCalendar(year, calendar.getMonth());
    } catch (NumberFormatException ee) {
    showYear.setText(" " + year);
    calendar.setYear(year);
    calendar.setCalendar(year, calendar.getMonth());
    }

    }
    }}-----------------------------------------------------------package calendar;import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;public class Month extends Box implements ActionListener {
    int month;
    JTextField showMonth = null;
    JButton nextMonth,lastMonth;
    MyCalendar calendar;
    public Month(MyCalendar calendar) {
    super(BoxLayout.X_AXIS);
    this.calendar = calendar;
    showMonth = new JTextField(2);
    month = calendar.getMonth();
    showMonth.setEditable(false);
    showMonth.setForeground(Color.blue);
    showMonth.setFont(new Font("TimesRoman", Font.BOLD, 16));
    nextMonth = new JButton("nextMonth");
    lastMonth = new JButton("lastMonth");
    add(lastMonth);
    add(showMonth);
    add(nextMonth);
    lastMonth.addActionListener(this);
    nextMonth.addActionListener(this);
    showMonth.setText(" " + month);
    }
    public void setMonth(int month) {
    if(month<=12 && month>=1) {
    this.month = month;
    } else {
    this.month = 1;
    }
    showMonth.setText(" " + month);
    }
    public int getMonth() {
    return month;
    }
    public void actionPerformed(ActionEvent e) {
    if(e.getSource() == lastMonth) {
    if(month >= 2) {
    month = month - 1;
    calendar.setMonth(month);
    calendar.setCalendar(calendar.getYear(), month);
    } else  if(month == 1) {
    month = 12;
    calendar.setMonth(month);
    calendar.setCalendar(calendar.getYear(), month);
    }
    showMonth.setText(" " + month);
    } else if(e.getSource() == nextMonth) {
    if(month < 12) {
    month = month + 1;
    calendar.setMonth(month);
    calendar.setCalendar(calendar.getYear(), month);
    } else if( month == 12) {
    month = 1;
    calendar.setMonth(month);
    calendar.setCalendar(calendar.getYear(), month);
    }
    showMonth.setText(" " + month);
    }

    }}晕,fireFox 不支持那个脚本的插件。。
    以前写的日历的程序