java - how to output the values from the arraylist -


now have modofied program according suggestions

    public class vehicle {      string colors[] = {"red", "white", "blue", "black", "silver"};     private string name;     private string model;     double cost_price;     int year;     int quantity;     double selling_price;     string registration_no; vehicle(){  }     vehicle(string name, string model, int year, double cost_price) {          this.name = name;         this.model = model;         this.year = year;         this.cost_price = cost_price;         this.quantity = 0;         this.selling_price = 0;     }      vehicle(string name, string model, int year,int quantity, double cost_price, string registration_no) {         this(name, model, year, cost_price);         this.quantity=quantity;         this.selling_price = cost_price;         this.registration_no = registration_no;     }      public void setname(string name) {         this.name = name;     }      public void setmodel(string model) {         this.model = model;     }      public string getname() {         return name;     }      public string getmodel() {         return model;     }      public double calsellingprice(int markup) {          return cost_price + ((cost_price * markup) / 100);     }      public int updatequantity(int amount) {        return amount;     }   public string tostring() {      return "name=" + this.name + ", model=" + this.model + ", cost_price=" + this.cost_price + ", year=" + this.year + ", quantity=" + this.quantity + "selling_price=" + this.selling_price+ ", registration=" + registration_no; }     /**      * @param args command line arguments      */ }  class vehicletest {    arraylist uwimotors = new arraylist();       public static void main(string[] args) {         // todo code application logic here scanner sc= new scanner(system.in);        vehicle v1 = new vehicle("ferrari", "enzo", 2011, 6, 250000, "pk07lvd");          vehicle v2 = new vehicle("audi", "r8", 2008,9, 550000,"addy104");          vehicle v3 = new vehicle("rangerover", "evoque", 2010,3, 578000,"ohz2692");          vehicle v4 = new vehicle("lamborghine", "aventador", 2013,5, 980000,"bb03813");          vehicle v5 = new vehicle("porsche", "carrera", 2006,15, 675000, "bd51smr");         vehicletest vt= new vehicletest();          vt.uwimotors.add(v1);         vt.uwimotors.add(v2);         vt.uwimotors.add(v3);         vt.uwimotors.add(v4);         vt.uwimotors.add(v5);      system.out.println("vehicle"); (int = 0; < vt.uwimotors.size(); i++) {                 vehicle vehicle  = (vehicle)vt.uwimotors.get(i);                 system.out.println(vehicle);             } (int = 0; < vt.uwimotors.size(); i++) {                 vehicle vehicle  = (vehicle)vt.uwimotors.get(i);                vehicle.selling_price=vehicle.calsellingprice(20);      }  (int = 0; < vt.uwimotors.size(); i++) {                 vehicle vehicle  = (vehicle)vt.uwimotors.get(i);  }       } 

}

i have modified program seems still not overriding tostring method again there doing wrong? please me need urgently

for time being let ignore bad coding practises in code. hope following code looking for?

      (int = 0; < uwimotors.size(); i++) {                     vehicle vehicle  = (vehicle)uwimotors.get(i); //                 system.out.println(vehicle.cost_price+","+vehicle.quantity); system.out.println(vehicle);// if vehicle object overrides tostring method                   } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -