|
下面是我写的代码 以为import类的问题一直编辑不过去~~~
那位朋友可以帮我看看,如何定义多个类
就是比如 java.util.Arrays java.util.ArrayList 我要用到这两个方法我该如何的去定义类那?
请指点~~~如果我教材看就更好了~~~
- import javax.swing.*;
- import java.util.*;
- import java.util.Arrays;
- import java.lang.Comparable;
- public class AdminHouro
- {
- public static void main(String[] args)
- {
- ArrayList staff = new ArrayList(); //java.util.ArrayList
-
- String input = JOptionPane.showInputDialog //java.swing.*
- ("how much money for A take");
- int k = Integer.parseInt(input);
- input = JOptionPane.showInputDialog
- ("how much money for B take");
- int k1 = Integer.parseInt(input);
- input = JOptionPane.showInputDialog
- ("how much money for C take");
- int k2 = Integer.parseInt(input);
- input = JOptionPane.showInputDialog
- ("How much add ");
- double add = Integer.parseInt(input);
- staff.add(new Emplogee("A",k,add));
- staff.add(new Emplogee("B",k1,add));
- staff.add(new Emplogee("c",k2,add));
- Arrays.sort(staff); //java.util.Arrays
- for(int i = 0; i < staff.size();i++)
- { Emplogee e = (Emplogee)staff.get(i);
- e.getAdd(add);
- }
- for(int i = 0;i < staff.size(); i++)
- {Emplogee e =(Emplogee) staff.get(i);
- System.out.println("name" + e.getName() + ",Omoney" + e.getOmoney() + ",Nmoney" + e.getNmoney());
- }
- }
- }
- class Emplogee implements Comparable //java.lang.Comparable
- {
- public Emplogee (String n ,double s, double add)
- { name = n;
- money = s;
- Hadd = add;
- }
- public String getName()
- {
- return name;
- }
- public double getOmoney()
- {
- return money;
- }
- public double getNmoney()
- {
- return Hadd;
- }
- public void getAdd(double byPercent)
- {
- double raise = money * byPercent / 100;
- Hadd = raise + money;
- }
- /**bi jiao shi yong "Hadd" zhe ge shu
- */
- public int CompareTo(Object otherObject)
- {
- Emplogee other = (Emplogee)otherObject;
- if (Hadd < other.Hadd) return -1;
- if (Hadd > other.Hadd) return 1;
- return 0;
- }
- private String name;
- private double money;
- private double Hadd;
- }
复制代码 |
|