Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions _1_basics/src/main/java/code/_3_in_class/bunaZiua.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package code._3_in_class;

public class bunaZiua {
public static void main(String[] args) {
System.out.println("buna ziua");
}
}

30 changes: 30 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/Boxer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package code._3_in_class;
import java.util.Random;

public class Boxer {
String nume;
int health=100;
int damagePerAttack=10;

public Boxer(String nume, int health, int damagePerAttack){
this.nume=nume;
this.health=health;
this.damagePerAttack=damagePerAttack;
}
public Boxer(String nume){
this.nume=nume;
}

public void attak(Boxer opponent){
int defendValue=(this.damagePerAttack*this.defend())/100;
opponent.health=opponent.health-(this.damagePerAttack+this.defend())/100;
System.out.println(("defendValue: "+defendValue));
System.out.println(("newHealth: "+opponent.health));
}

public void defend() {
Random random=new Random();
int defendPerc = random.nextInt(101);
return defendPerc;
}
}
22 changes: 22 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/BruceLee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package code._3_in_class;

public class BruceLee {
String nume;
int health=100;
int damagePerAttack=10;

public Boxer(String nume, int health, int damagePerAttack){
this.nume=nume;
this.health=health;
this.damagePerAttack=damagePerAttack;
}
public Boxer(String nume){
this.nume=nume;
}

void attak(Boxer opponent){
opponent.health=0;
}
void defend(){}
}

7 changes: 7 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/IBoxer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package code._3_in_class;

public interface IBoxer {
public void attack(Boxer opponent);
public int defent();

}
27 changes: 26 additions & 1 deletion _2_oo/src/main/java/code/_3_in_class/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
package code._3_in_class;

import java.util.Random;
public class Main {

public static void main(String[] args) {
//TODO put your code changes in here
IBoxer ion=new Boxer("ion", 100, 10);
IBoxer vasile=new Boxer("vasile");

startBoxingMatch(ion, vasile);
announceVictory(ion);
}
private static void announceVictory(Boxer ion) {
if(ion.health<=0)
System.out.println("vasile goooo");
else
System.out.println("ion gooooo");
}

//startingBoxingMatch


private static void startBoxingMatch(Boxer ion, Boxer vasile){
Random random= new Random();
while (ion.health>0 && vasile.health>0){
int zeroOrOne= random.nextInt(2);
if(zeroOrOne==0)
ion.attak((vasile));
else
vasile.attak((ion));
}
}
}
8 changes: 8 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/interface01.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package code._3_in_class;

public interface interface01 {
default void m(){
System.out.println("helllo from m()");
}
}

5 changes: 5 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/interface02.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package code._3_in_class;

public interface interface02 {
default void m2
}
13 changes: 13 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/someRandomClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package code._3_in_class;

public class someRandomClass implements interface01, interface02{
public static void main(){
someRandomClass c= new someRandomClass();
c.m();
}

@Override
public void m(){
interface02.super.m();
}
}
23 changes: 23 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/superBoxer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package code._3_in_class;

public class superBoxer implements IBoxer {
String nume;
int health=100;
int damagePerAttack=10;

public Boxer(String nume, int health, int damagePerAttack){
this.nume=nume;
this.health=health;
this.damagePerAttack=damagePerAttack;
}
public superBoxer(String nume){
this.nume=nume;
}
@Override
public void attack(Boxer opponent){

}

@Override
public void defent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@

public class ChessBoard {

public static int MAX_BOARD_WIDTH = 7;
public static int MAX_BOARD_HEIGHT = 7;
public static int MAX_BOARD_WIDTH = 8;
public static int MAX_BOARD_HEIGHT = 8;

private Pawn[][] pieces;

public ChessBoard() {
pieces = new Pawn[MAX_BOARD_WIDTH][MAX_BOARD_HEIGHT];
}

public void add(Pawn piece, int xCoordinate, int yCoordinate, PieceColor pieceColor) {
if (isLegalBoardPosition(xCoordinate, yCoordinate)) {
piece.setXCoordinate(xCoordinate);
piece.setYCoordinate(yCoordinate);
piece.setPieceColor(pieceColor);
pieces[xCoordinate][yCoordinate] = piece;
}
}

public void Add(Pawn pawn, int xCoordinate, int yCoordinate, PieceColor pieceColor) {
throw new UnsupportedOperationException("Need to implement ChessBoard.add()");
public boolean isLegalBoardPosition(int xCoordinate, int yCoordinate) {
return xCoordinate >= 0 && xCoordinate < MAX_BOARD_WIDTH &&
yCoordinate >= 0 && yCoordinate < MAX_BOARD_HEIGHT;
}

public boolean IsLegalBoardPosition(int xCoordinate, int yCoordinate) {
throw new UnsupportedOperationException("Need to implement ChessBoard.IsLegalBoardPosition()");
public Pawn getPiece(int xCoordinate, int yCoordinate) {
if (isLegalBoardPosition(xCoordinate, yCoordinate)) {
return pieces[xCoordinate][yCoordinate];
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public enum MovementType {

MOVE, CAPTURE;
MOVE, FORWARD, CAPTURE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ public Pawn(PieceColor pieceColor) {
this.pieceColor = pieceColor;
}

public ChessBoard getChesssBoard() {
return chessBoard;
}

public void setChessBoard(ChessBoard chessBoard) {
this.chessBoard = chessBoard;
}
Expand All @@ -39,21 +35,55 @@ public PieceColor getPieceColor() {
return this.pieceColor;
}

private void setPieceColor(PieceColor value) {
void setPieceColor(PieceColor value) {
pieceColor = value;
}

public void Move(MovementType movementType, int newX, int newY) {
throw new UnsupportedOperationException("Need to implement Pawn.Move()");
private boolean isValidForwardMove(int newX, int newY) {
int direction = (pieceColor == PieceColor.WHITE) ? 1 : -1;
if (newX == xCoordinate + direction && newY == yCoordinate) {
return chessBoard.isLegalBoardPosition(newX, newY) && chessBoard.getPiece(newX, newY) == null;
}
return false;
}


public void move(MovementType movementType, int newX, int newY) {
if (movementType == MovementType.FORWARD) {
if (isValidForwardMove(newX, newY)) {
chessBoard.getPiece(xCoordinate, yCoordinate).setXCoordinate(newX);
chessBoard.getPiece(xCoordinate, yCoordinate).setYCoordinate(newY);
chessBoard.add(chessBoard.getPiece(xCoordinate, yCoordinate), newX, newY, pieceColor);
chessBoard.add(null, xCoordinate, yCoordinate, null);
}
} else if (movementType == MovementType.CAPTURE) {
if (isValidCaptureMove(newX, newY)) {
chessBoard.add(null, newX, newY, null);
chessBoard.getPiece(xCoordinate, yCoordinate).setXCoordinate(newX);
chessBoard.getPiece(xCoordinate, yCoordinate).setYCoordinate(newY);
chessBoard.add(chessBoard.getPiece(xCoordinate, yCoordinate), newX, newY, pieceColor);
chessBoard.add(null, xCoordinate, yCoordinate, null);
}
}
}

private boolean isValidCaptureMove(int newX, int newY) {
int direction = (pieceColor == PieceColor.WHITE) ? 1 : -1;
if (newX == xCoordinate + direction && Math.abs(newY - yCoordinate) == 1) {
return chessBoard.isLegalBoardPosition(newX, newY) && chessBoard.getPiece(newX, newY) != null &&
chessBoard.getPiece(newX, newY).getPieceColor() != pieceColor;
}
return false;
}


@Override
public String toString() {
return CurrentPositionAsString();
return currentPositionAsString();
}

protected String CurrentPositionAsString() {
protected String currentPositionAsString() {
String eol = System.lineSeparator();
return String.format("Current X: {1}{0}Current Y: {2}{0}Piece Color: {3}", eol, xCoordinate, yCoordinate, pieceColor);
return String.format("Current X: %d%sCurrent Y: %d%sPiece Color: %s", xCoordinate, eol, yCoordinate, eol, pieceColor);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package clean.code.design_patterns.requirements.Iterator.src;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;

public class DiscJockey {

SongsOfThe70s songs70s;
SongsOfThe80s songs80s;
SongsOfThe90s songs90s;

SongIterator iter70sSongs;
SongIterator iter80sSongs;
SongIterator iter90sSongs;


public DiscJockey(SongIterator newSongs70s, SongIterator newSongs80s, SongIterator newSongs90s) {

iter70sSongs = newSongs70s;
iter80sSongs = newSongs80s;
iter90sSongs = newSongs90s;

}
public void showTheSongs(){

Iterator Songs70s = iter70sSongs.createIterator();
Iterator Songs80s = iter80sSongs.createIterator();
Iterator Songs90s = iter90sSongs.createIterator();

System.out.println("Songs of the 70s\n");
printTheSongs(Songs70s);
// :)
System.out.println("Songs of the 80s\n");
printTheSongs(Songs80s);

System.out.println("Songs of the 90s\n");
printTheSongs(Songs90s);

}

public void printTheSongs(Iterator iterator){

while(iterator.hasNext()){

SongInfo songInfo = (SongInfo) iterator.next();

System.out.println(songInfo.getSongName());
System.out.println(songInfo.getBandName());
System.out.println(songInfo.getYearReleased() + "\n");

}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package clean.code.design_patterns.requirements.Iterator.src;

public class RadioStation {

public static void main(String[] args){

SongsOfThe70s songs70s = new SongsOfThe70s();
SongsOfThe80s songs80s = new SongsOfThe80s();
SongsOfThe90s songs90s = new SongsOfThe90s();

DiscJockey album = new DiscJockey(songs70s, songs80s, songs90s);

// madMike.showTheSongs();

album.showTheSongs();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package clean.code.design_patterns.requirements.Iterator.src;

public class SongInfo{

String songName;
String bandName;
int yearReleased;

public SongInfo(String newSongName, String newBandName, int newYearReleased){
songName = newSongName;
bandName = newBandName;
yearReleased = newYearReleased;
}

public String getSongName(){
return songName;
}
public String getBandName(){
return bandName;
}
public int getYearReleased(){
return yearReleased;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package clean.code.design_patterns.requirements.Iterator.src;

import java.util.Iterator;

public interface SongIterator {

public Iterator createIterator();

}
Loading