|
@@ -0,0 +1,38 @@
|
|
|
|
+package com.sf.day06;
|
|
|
|
+
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+
|
|
|
|
+public class Car {
|
|
|
|
+ double weight;
|
|
|
|
+
|
|
|
|
+ int horsepower;
|
|
|
|
+ public double proportion(){
|
|
|
|
+ return horsepower*10*1.0/weight;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String toString() {
|
|
|
|
+ return "Car{" +
|
|
|
|
+ "weight=" + weight +
|
|
|
|
+ ", horsepower=" + horsepower +
|
|
|
|
+ "proportion = "+proportion()+
|
|
|
|
+ '}';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ Car[] cars = new Car[3];
|
|
|
|
+ Car car1 = new Car();
|
|
|
|
+ car1.weight = 1500;
|
|
|
|
+ car1.horsepower = 180;
|
|
|
|
+ Car car2 = new Car();
|
|
|
|
+ car2.weight = 1300;
|
|
|
|
+ car2.horsepower = 125;
|
|
|
|
+ Car car3 = new Car();
|
|
|
|
+ car3.weight = 2000;
|
|
|
|
+ car3.horsepower = 130;
|
|
|
|
+ cars[0] = car1;
|
|
|
|
+ cars[1] = car2;
|
|
|
|
+ cars[2] = car3;
|
|
|
|
+ System.out.println(Arrays.toString(cars));
|
|
|
|
+ }
|
|
|
|
+}
|