/JavaSE/Obiecte/src/Smartphone.java |
New file
@@ -0,0 +1,81 @@ |
|
public class Smartphone { |
|
String model; |
int pb; |
int k; |
boolean stare; |
|
Smartphone(){ |
|
k = 1; |
model = "Samsung S4"; |
System.out.println("Telefon " +model+" construit."); |
pb = 100; |
afiseazaBaterie(); |
} |
|
Smartphone(String model){ |
|
this.model = model; |
k = 1; |
System.out.println("Telefon " +model+" construit."); |
pb = 100; |
afiseazaBaterie(); |
} |
|
Smartphone(String model, int k){ |
|
this.model = model; |
this.k = k; |
System.out.println("Telefon " +model+" construit."); |
pb = 100; |
afiseazaBaterie(); |
} |
|
void afiseazaBaterie() { |
System.out.println("Baterie=" + pb + "% model="+model); |
} |
|
void incarca() { |
if (pb < 100) |
pb++; |
afiseazaBaterie(); |
// System.out.println("Incarcat="+pb+"%"); |
} |
|
void pornesteOpreste(){ |
if(stare==false){ |
stare = true; |
System.out.println("Telefon pornit!"); |
} |
else{ |
stare = false; |
System.out.println("Telefon oprit!"); |
} |
} |
|
|
|
void apeleaza() { |
if(stare==false){ |
System.out.println("Telefon oprit! Nu poate fi utilizat!"); |
return; |
} |
if (pb <= k) { |
System.out.println("Telefon "+model+" descarcat!"); |
} else { |
System.out.println("Telefonul "+model+" este utilizat."); |
pb = pb - k; |
afiseazaBaterie(); |
} |
} |
|
public static void main(String[] args) { |
Smartphone t1 = new Smartphone(); |
|
t1.pornesteOpreste(); |
|
|
} |
} |
/JavaSE/Obiecte/src/CoffeTest.java |
New file
@@ -0,0 +1,58 @@ |
public class CoffeTest { |
|
public static void main(String[] args) { |
CoffeMaker maker1 = new CoffeMaker(); |
|
Coffee[] pachet = new Coffee[10]; |
for (int i = 0; i < pachet.length; i++) { |
pachet[i] = maker1.getCofee(); |
} |
|
for (int i = 0; i < pachet.length; i++) { |
pachet[i].drinkCofee(); |
} |
|
} |
} |
|
class CoffeMaker{ |
CaffeineTank ctank = new CaffeineTank(); |
WaterTank wtank = new WaterTank(); |
CoffeMaker(){ |
System.out.println("New cofee maker created."); |
} |
Coffee getCofee(){ |
int w = wtank.getIngredient(); |
int c = ctank.getIngredient(); |
return new Coffee(w,c); |
} |
} |
|
class CaffeineTank{ |
CaffeineTank(){ |
System.out.println("New coffeine tank created."); |
} |
int getIngredient(){ |
return (int)(Math.random()*10); |
} |
} |
|
class WaterTank{ |
WaterTank(){ |
System.out.println("New water tank created."); |
} |
int getIngredient(){ |
return (int)(Math.random()*40); |
} |
} |
|
class Coffee { |
int water; |
int caffeine; |
Coffee(int water, int caffeine){ |
this.water = water;this.caffeine= caffeine; |
} |
void drinkCofee(){ |
System.out.println("Drink cofee [water="+water+":coffe="+ caffeine+"]"); |
} |
} |
/JavaSE/Obiecte/src/SmartphoneV2.java |
New file
@@ -0,0 +1,92 @@ |
class Baterie{ |
int pb; |
Baterie(){ |
pb = 100; |
} |
|
boolean utilizeaza(int x){ |
if(pb<=x){ |
System.out.println("Baterie descarcata!"); |
return false; |
} |
pb = pb - x; |
return true; |
} |
|
void incarca(){ |
if(pb<100) |
pb++; |
afiseaza(); |
} |
|
void afiseaza(){ |
System.out.println("Baterie "+pb+"%"); |
} |
} |
|
public class SmartphoneV2 { |
static int contor; |
String model; |
int k; |
Baterie b; |
|
SmartphoneV2(String model, int k){ |
contor++; |
this.model = model; |
this.k = k; |
System.out.println("Telefon " +model+" construit."); |
afiseazaBaterie(); |
} |
|
void afiseazaBaterie() { |
if(b!=null) |
b.afiseaza(); |
else |
System.out.println("Telefonul nu are baterie!"); |
} |
|
void incarca() { |
if(b!=null) |
b.incarca(); |
else |
System.out.println("Telefonul nu are baterie!"); |
} |
|
void seteazaBaterie(Baterie b){ |
if(b!=null){ |
System.out.println("Se inlocuieste baterie!"); |
}else{ |
System.err.println("Se instaleaza baterie!"); |
} |
this.b = b; |
} |
|
void apeleaza() { |
System.out.println("Apelare"); |
if(b==null){ |
System.out.println("Telefonul nu are baterie."); |
return; |
} |
|
if(b.utilizeaza(k)==false){ |
System.out.println("Baterie telefon descarcata."); |
}else{ |
System.out.println("Telefonul "+model+" este utilizat."); |
} |
} |
|
public static void main(String[] args) { |
|
SmartphoneV2 t4 = new SmartphoneV2("Nexus 4",3); |
|
t4.apeleaza(); |
|
Baterie b1 = new Baterie(); |
|
t4.seteazaBaterie(b1); |
|
t4.apeleaza(); |
|
System.out.println("Telefone construite = "+SmartphoneV2.contor); |
} |
} |
/JavaSE/Obiecte/.settings/org.eclipse.jdt.core.prefs |
New file
@@ -0,0 +1,11 @@ |
eclipse.preferences.version=1 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 |
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
org.eclipse.jdt.core.compiler.compliance=1.7 |
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
org.eclipse.jdt.core.compiler.source=1.7 |