Biblioteca Java

Subversion Repositories:
Compare Path: Rev
With Path: Rev
/JavaSE/ @ 37  →  /JavaSE/ @ 38
New file
/JavaSE/Obiecte/.classpath
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
New file
/JavaSE/Obiecte/.project
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Obiecte</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
New file
/JavaSE/Obiecte/src/Test.java
@@ -0,0 +1,16 @@
 
public class Test {
 
public static void main(String[] args) {
Senzor s1 = new Senzor();
Senzor s2 = new Senzor();
s1.value = 100;
s2.value = 200;
System.out.println("Senzor s1:"+s1.value);
System.out.println("Senzor s2:"+s2.value);
 
}
 
}
New file
/JavaSE/Obiecte/src/Senzor.java
@@ -0,0 +1,22 @@
 
public class Senzor {
static int k;
int value;
boolean active;
public static void main(String[] args) {
Senzor s1 = new Senzor();
Senzor s2 = new Senzor();
s1.value = 100;
s2.value = 200;
s1.k = 50;
System.out.println("Senzor s1:"+s1.value);
System.out.println("Senzor s2:"+s2.value);
System.out.println("Senzor s1 k:"+s1.k);
System.out.println("Senzor s2 k:"+s2.k);
System.out.println("Senzor s2 k:"+Senzor.k);
}
}
New file
/JavaSE/Obiecte/src/Smartphone.java
@@ -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();
 
}
}
New file
/JavaSE/Obiecte/src/CoffeTest.java
@@ -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+"]");
}
}
New file
/JavaSE/Obiecte/src/SmartphoneV2.java
@@ -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);
}
}
New file
/JavaSE/Obiecte/src/Telefon.java
@@ -0,0 +1,28 @@
 
public class Telefon {
int pb;
Telefon(){
pb = 100;
}
Telefon(int pb){
this.pb = pb;
}
void afiseaza(){
System.out.println("Telefon baterie "+pb+"%");
}
public static void main(String[] args) {
Telefon t1 = new Telefon();
t1.afiseaza();
/* Telefon t2 = new Telefon();
t2.afiseaza();
Telefon t3 = new Telefon(15);
t3.afiseaza();*/
}
}
New file
/JavaSE/Obiecte/.settings/org.eclipse.jdt.core.prefs
@@ -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