Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CRUD vehicules
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.ListIterator; class Vehicule { private int id; private String type; private List<Vehicule> list; private String immat; private int key; public Vehicule() { list = new ArrayList<Vehicule>(); for(int i=0;i<5;i++) { list.add(new Vehicule(i,"C4","QQ ZZ 36")); } key=5; } public Vehicule(int id, String type, String immat) { super(); this.id = id; this.type = type; this.immat = immat; } public void modVehicule(int id, String type, String immat) { for(int i=0;i< this.list.size();i++) if (this.list.get(i).id == id) { this.list.get(i).type = type; this.list.get(i).immat = immat; } } public int addVehicule(String type, String immat) { list.add(new Vehicule(key++,type,immat)); return this.key; } public int delVehicule(int id) { list.remove(id); return this.key; } public List<Vehicule> getList() { return this.list; } public void setType(String type) { this.type = type; } public String getType() { return type; } public String getImmat() { return immat; } public void setImmat(String immat) { this.immat = immat; } public String toString() { return "id:" + id + " - Type:" + type + " - Immat:" + immat; } } class Event { private int id; private boolean uso; private String etat; public Event(int id, String type) { this.id = id; this.uso = type.equals("uso"); if (this.uso) etat="en attente"; if (id==4) etat="indispo"; } public void setEtat(String etat) { this.etat = etat; } public String getEtat() { return etat; } public void setId(int id) { this.id = id; } public int getId() { return id; } public void setUso(boolean uso) { this.uso = uso; } public boolean isUso() { return uso; } public String toString() { return "id:" + id + " - uso:" + uso + " - etat:" + etat; } } class Rextester { public static List<Event> list; public static void main(String args[]) { Event evt = new Event(5,"uso"); int id = evt.getId(); Vehicule vh = new Vehicule(); //for(Vehicule v : vh.getList()) //System.out.println(v.toString()); vh.modVehicule(2,"modele","immat"); vh.addVehicule("C4","QQ 34"); vh.delVehicule(3); for(Vehicule v : vh.getList()) System.out.println(v.toString()); } }
run
|
edit
|
history
|
help
0
4b
2b
Coding Challenge - 04 (Perfect numbers)
Link document
Java Variable
СОРТИРОВКА СЛИЯНИЕМ
Jh
Odd Occurence Problem Template
Coding Challenge - 01 (Even numbers)
rextester.java1