Sunteți pe pagina 1din 9

Lab1

import java.util.*;

public class Sultan {

private double gold;


private int harem;
private byte beauty[];
private byte badness[];
static int sultani;
private Scanner inp = new Scanner(System.in);

public Sultan() //constr default


{
gold=10000;
harem=10;
beauty=new byte[100];
for(byte a=0;a<40; a++)
beauty[a]=beauty[++a];
badness=new byte[100];
for(byte i=0;i<35; i++)
badness[i]=badness[++i];
sultani++;
}

public Sultan(double bani, int femei) //constr cu 2 parametri


{
gold=bani;
harem=femei;
beauty=new byte[100];
badness=new byte[100];
sultani++;
}

public Sultan(Sultan Copiere) //constr de copiere


{
gold=Copiere.gold;
harem=Copiere.harem;
beauty=new byte[100];

for(byte a=0;a<100; a++)


{
beauty[a]=Copiere.beauty[a];
}
badness=new byte[100];
for(byte i=0;i<100; i++)
{
badness[i]=Copiere.badness[i];
}
sultani++;
}

/////seter si geter
public double get_Gold() {
return gold;
}

public void set_Gold(double aur)


{

gold=aur;

public int get_Harem()


{
return harem;
}

public void set_Harem(int femei)


{
if(femei<10)
harem=femei;
}

public byte[] get_Beauty()


{
return beauty;
}

public void set_beauty(byte criteria)


{
for(byte i=0; i<100 ;i++)
{
if(i>=40)

beauty[i]=criteria;
}

}
public byte[] get_Badness()
{
return badness;
}

public void set_Badness(byte criteria)


{
for(byte i=0; i<100 ;i++)
{
if(i>=40)

beauty[i]=criteria;
}
}

////metoda de afisare
public void completare()
{
System.out.println("gold=");
gold = inp.nextDouble();

System.out.println("harem=");
harem = inp.nextInt();
System.out.println("Introduceti valorile frumusetii: ");
for(int i =0; i<beauty.length;i++)
beauty[i] = inp.nextByte();
System.out.println("Introduceti valorile rautaciunii: ");
for(int i =0; i<badness.length;i++)
badness[i] = inp.nextByte();
}
////metoda random
public void random()
{
Random r = new Random();
gold = r.nextDouble();
harem = r.nextInt();
for(i=0;i<beauty.lenght;i++)
beauty =r.nextByte();
for(i=0;i<badness.lenght;i++)
badness =r.nextByte();

}
public static void comp(Sultan s1, Sultan s2) {
if(s1.get_Harem() > s2.get_Harem()) {
System.out.println("primul sultan are mai multe
sotii");
}
else System.out.println("Al 2 sultan are mai multe
sotii");
if(s1.get_Harem() == s2.get_Harem())
System.out.println("nr egal de sotii");
}
// pentru a calcula sanatea avem med_beaty/med_badness
private double med(byte[] x) {
double m = 0;
for(int i = 0 ; i < x.length; i++)
m += x[i];
return m/x.length;
}

public double coef_sanatate() {


return (med(get_Beauty())/med(get_Badness()));
}

//afisare
public void afisare( )
{System.out.println("gold=" +gold);
System.out.println("harem=" +harem);
for(int i=0;i<beauty.length;i++)
System.out.println("beauty["+ i + "]=" +beauty);
for(int i=0;i<badness.length;i++)
System.out.println("badness["+ i + "]=" +badness);
}

public static void main(String[] args) {

Sultan[] sultani = new Sultan[3];


sultani[0] = new Sultan();
sultani[1] = new Sultan(1000, 101);
sultani[2] = new Sultan(sultani[1]);
Sultan.comp(sultani[0], sultani[1]);

Sultan Mustafa = new Sultan();


Mustafa.afisare();
Sultan Mehmet = new Sultan(5000,99);
Mehmet.afisare();
}
}

Lab 2

package games;

public class strategy extends Gen implements grafica{ //abstractizam


clasa
int anul;
String platforma;
byte limita_virsta;

strategy()
{
super();
anul=2005;
platforma="pc";
limita_virsta=16;

}
strategy(String p,double q,String n,int d,byte l)
{
super(p,q);
platforma=n;
anul=d;
limita_virsta=l;

public void afisare()


{
super.afisare();
System.out.println("Jocul a fost lansat in anul " + anul );
System.out.println("Platforma jocului este " + platforma);
System.out.println("limita de virsta este " + limita_virsta);
}

public void calitate()


{
if( anul>2005)
System.out.println("grafica slaba");
else System.out.println("grafica buna");
}

void porneste()
{
if(limita_virsta<16)
System.out.println("jocul a pornit");
}

public void viteza()


{
if (anul>2005)
System.out.println("viteza depaseste 20fps");
else System.out.println("viteza nu depaseste 20fps");
}

package games;

public interface grafica {


public void calitate();

package games;

public abstract class Gen implements grafica{

String nume;
double dimensiunea;

Gen()
{
nume="Half-Life";
dimensiunea=46.7;//dimensiunea in Mb
}

Gen(String n,double d)
{
nume=n;
dimensiunea=d;
}
public void afisare()
{System.out.println("------Informatia------- ");
System.out.println("Numele este "+nume);
System.out.println("Dimensiunea este "+dimensiunea);

abstract void viteza();

package games ;

class Games {

public static void main(String[] args) {

/* Apelarea constructorilor superclasei si metodelor ei*/


Gen Empire=new strategy("MetalGear
Rising",12.5,"PC",2014,(byte)16);
Empire.afisare();
Empire.calitate();
Empire.viteza();

/*Metode proprii ale claselor mostenite*/


strategy Rome_totalwar=new strategy();
Rome_totalwar.afisare();
Rome_totalwar.porneste();
Rome_totalwar.calitate();
Rome_totalwar.viteza();

action DMC=new action("Devil may


Cry",3.45,24,"Dante",300,30);
DMC.afisare();
DMC.time_up();
DMC.supreme();
DMC.calitate();
DMC.viteza();

Gen Dishonored=new action();


Dishonored.afisare();
Dishonored.calitate();

Gen[] vector;
vector = new Gen[4];

for(int i=0;i<vector.length;i+=2) {

vector[i]=new strategy();
vector[i+1]=new action();
vector[i].afisare();
vector[i+1].viteza();
vector[i].calitate();
((strategy)vector[i]).porneste();
((action)vector[i+1]).time_up();

for(int i=0;i<vector.length; i++)


{
if(vector[i] instanceof action)
{
((action)vector[i]).time_up();
}

}
}

package games;

public class action extends Gen implements grafica


{
int nr_stadii;
String Nume_personaj;
String Skill;
int Mana;
int Time;
static int rating;
action()
{
super();
nr_stadii=24;
Nume_personaj="Emily Colduin";
Skill="Shadow";
Mana=250;
Time=30;
rating ++;
}

action(String a,double b, int t)


{
super(a,b);
nr_stadii=24;
Nume_personaj="Handsome Jack";
Skill="Dark";
Mana=400;
Time=t;
rating ++;
}
action(String e,double f, int a,String b,int c,int d)
{
super(e,f);
nr_stadii=a;
Nume_personaj=b;
Skill="Rebellion";
Mana=c;
Time=d;
rating ++;
}

action(String f,double g, int a ,String b,String c,int d, int e)


{
super(f,g);
nr_stadii=a;
Nume_personaj=b;
Skill=c;
Mana=d;
Time=e;
rating ++;
}
void time_up()
{
if(Time<30)
System.out.println("Game Over");

public void afisare()


{

super.afisare();
System.out.println("Jocul are numarul de stadii egal cu
"+nr_stadii);
System.out.println("Numele personajului este
"+Nume_personaj);
System.out.println("Puterea specifica a personajului este
"+Skill);
System.out.println("Mana personajului este "+Mana);
System.out.println("Ratingul jocului este "+rating);

public void viteza()


{
if(nr_stadii<20)
System.out.println("viteza va fi minim 30fps");
}

public void calitate()


{
if(Mana<200)
System.out.println("Personajul nu va putea dobori
ultimul boss");
else
System.out.println("Personajul la sigur va trece de
ultimul boss");

public final void supreme()///nu poate fi descrisa


{

if (Mana>300)
System.out.println("Ati deschis nivelul bonus");
else System.out.println("Sorry restartati misiunea din
nou");
}
}