• Tidak ada hasil yang ditemukan

public class CarElement { private String code

N/A
N/A
Protected

Academic year: 2025

Membagikan "public class CarElement { private String code"

Copied!
4
0
0

Teks penuh

(1)

public class CarElement { private String code;

private double price;

public CarElement (String code, double price){

this.code=code;

this.price=price;

}

public CarElement (CarElement c){

this.code=c.code;

this.price=c.price;

}

public void display(){

System.out.println("Code: "+code);

System.out.println("price: "+ price);

}

public double getprice(){

return price;

} }

public class Car { private int seatNb;

private int year;

private int ncel;

private CarElement e[];

public Car(int seatNb, int year, int size){

this.seatNb =seatNb;

this.year =year;

ncel=0;

e= new CarElement[size];

}

(2)

public void display(){

System.out.println("car information");

System.out.println("year :"+year);

System.out.println("seat nmber : " +seatNb);

for (int i=0; i< ncel;i++) e[i].display();

System.out.println("---");

}

public boolean isFull(){

return ncel==e.length;

}

public void copyCar (Car c){

this.name =c.name ; this.year =c.year ; this.id = c.id ;

this.seatNb = c.seatNb ; this.ncel = c.ncel ;

this.e =new CarElement [c.e.length ];

for(int i=0; i<this.ncel ;i++)

this.e[i]=new CarElement (c.e[i]);

}

public boolean addElement (CarElement ee){

if (isFull())

return false;

else {

e[ncel++]= new CarElement (ee);

return true;

} }

public double priceCar(){

double price =0;

for(int i =0; i<ncel;i++)

price += e[i].getprice();

return price;

}

public String getName(){

return name;

}

(3)

public String getId(){

return id;

}

public int getYear(){

return year;

} }

public class KSUCars { private int nbc;

private Car c[];

public KSUCars (int size){

c=new Car [size];

nbc=0;

}

public void display(){

System.out.println("========================");

for(int i=0; i< nbc; i++) c[i].display();

}

public boolean isEmpty(){

return nbc ==0;

}

public int searchCar (String Name){

for(int i=0;i<nbc;i++){

if (c[i].getName().equals(Name)) return i;

}

return -1;

}

(4)

public Car getCar(String Id){

for(int i =0;i<nbc;i++){

if(c[i].getId().equals(Id)) return c[i];

}

return null;

}

public Car removeCar (String Name){

int loc = searchCar (Name);

if (loc ==-1) return null;

else{

Car temp = c[loc];

for(int i= loc; i< nbc-1;i++) c[i] = c[i+1];

c[nbc-1]=null;

nbc--;

return temp;

} }

public double averagePice (int Year){

int count =0;

double total=0;

for(int i=0; i<nbc;i++) {

if (c[i].getYear()> Year) {count++;

total +=c[i].priceCar();

} }

if(count==0) return 0;

else return total/count;

} }

Referensi

Dokumen terkait

public class frmKomp extends javax.swing.JFrame { public String nama_file= &#34;&#34;;. public String

public class Daftar_kartu extends Activity {. private static

Example: MixedCounter public class MixedCounter { private static int sharedCounterValue = 0; private int counterValue = 0; public int count { sharedCounterValue++; return

Below is the definition of the Pen class: public class Pen{ private String colour; private boolean hasEraser; private int tipType; public PenString colour, int tipType, boolean

entities own/manage 1 1 2 2 2 2 3 1 ownership treatment Public utility Public utility local council Private golf course Public utility Private consortium Private investor

1.1 Public private partnerships in Europe 3 1.2 Public private partnerships in the United States 8 2.1 Classification of infrastructure by type 21 3.1 Range of public/private business

This idea of a public–private partnership PPP or P3 is an approach in which the resources of interested stakeholders from the public and private sector e.g., governmental authorities,

Jawaban: a Atribut/Field private int mProductID; private String mProductName; private double mPrice; private int mQuantity; b Konstruktor public Productint productID, String