还有学校没有讲到的,也多少写了点:以备后用了:摘出了其中一部分,限于篇幅就不全贴出来了,这毕竟是技术论坛,不该发这些菜鸟级的代码的
package tom.jiafei;
class Tom{
void speak(){
System.out.println("Tom类在tom.jiafei包中");
}
}
public class Example4_10{
public static void main(String args[]){
Tom cat=new Tom();
cat.speak();
System.out.println("Example4_10类也在tom.jiafei包中");
}
}
import java.util.Date;
public class Example4_11{
public static void main(String args[]){
Date date=new Date();
System.out.printf("本地机器的时间:\n%s",date);
}
}
import tom.jiafei.*;
public class Example4_12{
public static void main(String args[ ]){
SquareEquation equation=new SquareEquation(4,5,1);
equation.getRoots();
equation.setCoefficient(-3,4,5);
equation.getRoots();
}
}
public class Example4_13{
private int money;
Example4_13(){
money=2000;
}
private int getMoney(){
return money;
}
public static void main(String args[ ]){
Example4_13 exa=new Example4_13(); //对象exa在Example4_13类中
exa.money=3000;
int m=exa.getMoney();
System.out.println("money="+m);
}
}
贴图费劲,就不贴图了
class Lader{
double above,bottom,height;
Lader(){}
Lader(double a,double b,double h){
above=a;
bottom=b;
height=h;
}
public void setAbove(double a){
above=a;
}
public void setBottom(double b){
bottom=b;
}
public void setHeight(double h){
height=h;
}
double computeArea(){
return (above+bottom)*height/2.0;
}
}
public class Example4_1{
public static void main(String args[]){
double area1=0,area2=0;
Lader laderOne,l
package tom.jiafei;
class Tom{
void speak(){
System.out.println("Tom类在tom.jiafei包中");
}
}
public class Example4_10{
public static void main(String args[]){
Tom cat=new Tom();
cat.speak();
System.out.println("Example4_10类也在tom.jiafei包中");
}
}
import java.util.Date;
public class Example4_11{
public static void main(String args[]){
Date date=new Date();
System.out.printf("本地机器的时间:\n%s",date);
}
}
import tom.jiafei.*;
public class Example4_12{
public static void main(String args[ ]){
SquareEquation equation=new SquareEquation(4,5,1);
equation.getRoots();
equation.setCoefficient(-3,4,5);
equation.getRoots();
}
}
public class Example4_13{
private int money;
Example4_13(){
money=2000;
}
private int getMoney(){
return money;
}
public static void main(String args[ ]){
Example4_13 exa=new Example4_13(); //对象exa在Example4_13类中
exa.money=3000;
int m=exa.getMoney();
System.out.println("money="+m);
}
}
贴图费劲,就不贴图了
class Lader{
double above,bottom,height;
Lader(){}
Lader(double a,double b,double h){
above=a;
bottom=b;
height=h;
}
public void setAbove(double a){
above=a;
}
public void setBottom(double b){
bottom=b;
}
public void setHeight(double h){
height=h;
}
double computeArea(){
return (above+bottom)*height/2.0;
}
}
public class Example4_1{
public static void main(String args[]){
double area1=0,area2=0;
Lader laderOne,l