第一个问题,一个 Cup 类如下:public class Cup { private double volume, weight; private int color; public void pour () {} public void drink () {} public void setVolume (double volume) { this.volume = volume; } public void setWeight (double weight) { this.weight = weight; } public void setColor (int color) { this.color = color; } public double getVolume () { return volume; } public double getWeight () { return weight; } public int getColor () { return color; } public static void main (String args[]) { Cup cup = new Cup(); cup.drink(); cup.pour(); }}=================================================================第二个问题:public class Math { public double area (double radius) { return (0.5 * Math.PI * radius * radius); } public double area (double width, int height) { return (width * height); } public double sumOf (double arg0, double arg1) { return (arg0 + arg1); }}
不要这么懒,看样子是学生,东西还是要学的。public class Shui { private static Shui instance; private static int shuiliang; public static Shui getInstance(){ //实例化 if(instance == null){ instance = new Shui(); } return instance; } public static int heShui(int shui){ //喝水 shuiliang -= shui; return shuiliang; } public static int daoShui(int shui){ //倒水 shuiliang += shui ; return shuiliang; } }class MathUtils{ public static double getCircleS(int r){ //圆面积 return Math.PI*r*r; } public static int jiuxing(int a,int b){ //矩形面积 return a*b; } public static int twoSum(int a ,int b){ //任意2个数之合 return a+b; }}