bzu-java(二)
public class Vehicle{
private int speed;
private int size;
private void move(){};
public void speedUp(){
this.speed++;
}
public void speedDown(){
this.speed--;
}
public void setSpeed(int speed){
this.speed=speed;
}
public void setSize(int size){
this.size=size;
}
public static void main(String args[]){
Vehicle vehicle=new Vehicle();
vehicle.setSize(100);
vehicle.setSpeed(100);
System.out.println(vehicle.size);
System.out.println(vehicle.speed);
vehicle.speedUp();
System.out.println(vehicle.speed);
vehicle.speedDown();
System.out.println(vehicle.speed);
}
}
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class test2{
public static void main(String args[]){
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
System.out.println(df.format(new Date()));
Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
System.out.println( +hour + ":" +minute + ":" + second);
}
}
class Point{
private double x;
private double y;
public double getDis(Point point){
return Math.sqrt(Math.sqrt((point.x-this.x)*(point.x-this.x)+(point.y-this.y)*(point.y-this.y)));
}
Point(double x,double y){
this.x=x;
this.y=y;
}
}
public class Circle{
private Point point;
private float r;
Circle(){
this.point=new Point(1,5);
this.r=4;
}
Circle(double x,double y,float r){
this.point=new Point(x,y);
this.r=r;
}
public Point getPoint(){
return this.point;
}
public float getR(){
return this.r;
}
public static void main(String args[]){
Circle c1=new Circle();
Circle c2=new Circle(1,5,100);
if((c1.getPoint().getDis(c2.getPoint()))<(c1.getR()+c2.getR()))
System.out.println("重叠");
else System.out.println("不重叠");
}
}
public class Phone{
private SIM sim;
Phone(SIM sim){
this.sim=sim;
}
public void setSIM(SIM sim){
this.sim=sim;
}
public int getId(){
return this.sim.getID();
}
public static void main(String args[]){
SIM sim1=new SIM(1);
SIM sim2=new SIM(2);
Phone phone=new Phone(sim1);
System.out.println(phone.getId());
phone.setSIM(sim2);
System.out.println(phone.getId());
}
}
class SIM{
private int id;
SIM(int id){
this.id=id;
}
public int getID(){
return this.id;
}
}
public class test{
public static void main(String args[]){
CPU cpu=new CPU();
cpu.setSpeed(2200);
HardDisk disk=new HardDisk();
disk.setAmount(200);
PC pc=new PC();
pc.setCPU(cpu);
pc.setHardDisk(disk);
pc.show();
}
}
class CPU{
private int speed;
public void setSpeed(int speed){
this.speed=speed;
}
public int getSpeed(){
return speed;
}
}
class HardDisk{
private int amount;
public void setAmount(int amount){
this.amount=amount;
}
public int getAmount(){
return this.amount;
}
}
class PC{
private CPU cpu;
private HardDisk HD;
public void setCPU(CPU cpu){
this.cpu=cpu;
}
public void setHardDisk(HardDisk HD){
this.HD=HD;
}
public void show(){
System.out.println(this.cpu.getSpeed()+" "+this.HD.getAmount());
}
}