From 393f6c23d78717d9c89d231034fced43693df49a Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Fri, 20 Dec 2019 21:12:59 +0200 Subject: [PATCH 01/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java --- .../homework3/perimeterAndArea/MainApp.java | 46 ++++++++++++++++++ .../homework3/perimeterAndArea/Rectangle.java | 47 +++++++++++++++++++ .../homework3/perimeterAndArea/Shape.java | 10 ++++ .../homework3/perimeterAndArea/Square.java | 37 +++++++++++++++ .../pentastagiu/week3/ExternalApp.java | 37 --------------- 5 files changed, 140 insertions(+), 37 deletions(-) create mode 100644 src/com/pentalog/pentastagiu/homework3/perimeterAndArea/MainApp.java create mode 100644 src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Rectangle.java create mode 100644 src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Shape.java create mode 100644 src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Square.java delete mode 100644 src/com/pentalog/pentastagiu/week3/ExternalApp.java diff --git a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/MainApp.java b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/MainApp.java new file mode 100644 index 0000000..7dda605 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/MainApp.java @@ -0,0 +1,46 @@ +package com.pentalog.pentastagiu.homework3.perimeterAndArea; + +import com.sun.deploy.security.WinDeployNTLMAuthCallback; + +import java.util.ArrayList; +import java.util.List; + +public class MainApp { + + + + + public static void main(String[] args) { + List shapes = new ArrayList<>(); + Rectangle drept=new Rectangle(19,12); + System.out.println(drept.area()); + System.out.println(drept.perimeter()); + Square patra=new Square(11); + System.out.println(patra.area()); + System.out.println(patra.perimeter()); + shapes.add(drept); + + shapes.add(patra); + int ariaCeaMaiMare = 0; + + int index = 0; + int i = 0; + for (Shape shape : shapes) { +// System.out.println("shape = " + shape + " i" + i); + //adunare arie cea mai mare + if (ariaCeaMaiMare < shape.area()) { + + ariaCeaMaiMare = shape.area(); + index=shapes.indexOf(shape); + + } + i++; + } + System.out.println("Aria cea mai mare o are = " + shapes.get(index)); + + } + + + + +} diff --git a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Rectangle.java b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Rectangle.java new file mode 100644 index 0000000..60beaff --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Rectangle.java @@ -0,0 +1,47 @@ +package com.pentalog.pentastagiu.homework3.perimeterAndArea; + +public class Rectangle extends Shape { + + private static int width; + private static int length; + + public Rectangle(int width, int length) { + this.width = width; + this.length = length; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + + @Override + public int perimeter() { + return 2*(width+length); + } + + + public int area() { + return width*length; + } + + + + /* @Override + public String toString() { + return "Square{" + + "length" +length+ + "width= " + width + "area "+area()+"peimetru "+perimeter(); + }*/ +} diff --git a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Shape.java b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Shape.java new file mode 100644 index 0000000..84cc545 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Shape.java @@ -0,0 +1,10 @@ +package com.pentalog.pentastagiu.homework3.perimeterAndArea; + +public abstract class Shape { + + public abstract int perimeter(); + + public abstract int area(); + + +} diff --git a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Square.java b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Square.java new file mode 100644 index 0000000..5929579 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Square.java @@ -0,0 +1,37 @@ +package com.pentalog.pentastagiu.homework3.perimeterAndArea; + +public class Square extends Shape { + + private static int a; + + + public Square(int a) { + this.a = a; + } + + public int getA() { + return a; + } + + public void setA(int a) { + this.a = a; + } + + + public int perimeter() { + return 4*a; + } + + + public int area() { + return a*a; + } + + + + /* @Override + public String toString() { + return "Square{" + + "a='" + a + "area "+area()+"perimetru "+perimeter(); + }*/ +} diff --git a/src/com/pentalog/pentastagiu/week3/ExternalApp.java b/src/com/pentalog/pentastagiu/week3/ExternalApp.java deleted file mode 100644 index 6d9710c..0000000 --- a/src/com/pentalog/pentastagiu/week3/ExternalApp.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.pentalog.pentastagiu.week3; - -import com.pentalog.pentastagiu.week3.deposit.Box; -import com.pentalog.pentastagiu.week3.university.Student; - -// I added this class to put here the code I created in live demo on the Homework1 class to avoid conflicts for your pull requests done on for homework 1 -// (the purpose of this class is to see how import appears for Student and to test the visibility of the Student class -// if I declare it without an access modifier(default) or with public access modifier) -public class ExternalApp { - - public static void main(String[] args) { - Student student = new Student(); - - int originalValue = 10; - System.out.println("In main method, before modify: " + originalValue); - modify(originalValue); - System.out.println("In main method, after modify: " + originalValue); - - Box box = new Box(100,20,50,"blue"); - System.out.println("In main method, before modify: " + box.getLength()); - modify(box); - System.out.println("In main method, after modify: " + box.getLength()); - } - - private static void modify(Box box) { - System.out.println("In local method, before modify: " + box.getLength()); - box.setLength(2); - System.out.println("In local method, after modify: " + box.getLength()); - } - - private static void modify(int originalValue) { - System.out.println("In local method, before modify: " + originalValue); - originalValue = 5; - System.out.println("In local method, after modify: " + originalValue); - - } -} From 7443d8d96e28b6afc42a37344b1f1d0117ecd830 Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Fri, 20 Dec 2019 21:15:01 +0200 Subject: [PATCH 02/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../pentastagiu/homework3/perimeterAndArea/Rectangle.java | 4 ++-- .../pentastagiu/homework3/perimeterAndArea/Square.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Rectangle.java b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Rectangle.java index 60beaff..c39d411 100644 --- a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Rectangle.java +++ b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Rectangle.java @@ -38,10 +38,10 @@ public int area() { - /* @Override + @Override public String toString() { return "Square{" + "length" +length+ "width= " + width + "area "+area()+"peimetru "+perimeter(); - }*/ + } } diff --git a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Square.java b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Square.java index 5929579..71a4f16 100644 --- a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Square.java +++ b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/Square.java @@ -29,9 +29,9 @@ public int area() { - /* @Override + @Override public String toString() { return "Square{" + "a='" + a + "area "+area()+"perimetru "+perimeter(); - }*/ + } } From dc81faf6cd174aa8ae036c1dd4ca3a1d642faf4c Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Fri, 20 Dec 2019 21:32:36 +0200 Subject: [PATCH 03/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/restaurant/CalculateTaxes.java | 4 ++++ .../pentastagiu/homework3/restaurant/Restaurant.java | 11 +++++++++++ .../homework3/restaurant/VegetarianRestaurant.java | 4 ++++ 3 files changed, 19 insertions(+) create mode 100644 src/com/pentalog/pentastagiu/homework3/restaurant/CalculateTaxes.java create mode 100644 src/com/pentalog/pentastagiu/homework3/restaurant/Restaurant.java create mode 100644 src/com/pentalog/pentastagiu/homework3/restaurant/VegetarianRestaurant.java diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/CalculateTaxes.java b/src/com/pentalog/pentastagiu/homework3/restaurant/CalculateTaxes.java new file mode 100644 index 0000000..3b2ff43 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/restaurant/CalculateTaxes.java @@ -0,0 +1,4 @@ +package com.pentalog.pentastagiu.homework3.restaurant; + +public interface CalculateTaxes { +} diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/Restaurant.java b/src/com/pentalog/pentastagiu/homework3/restaurant/Restaurant.java new file mode 100644 index 0000000..0eed673 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/restaurant/Restaurant.java @@ -0,0 +1,11 @@ +package com.pentalog.pentastagiu.homework3.restaurant; + +public class Restaurant { + private int numberOfGuest; + private int income; + private int priceForMenu; + + public void acomodateGuest(){ + + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/VegetarianRestaurant.java b/src/com/pentalog/pentastagiu/homework3/restaurant/VegetarianRestaurant.java new file mode 100644 index 0000000..1a78ec2 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/restaurant/VegetarianRestaurant.java @@ -0,0 +1,4 @@ +package com.pentalog.pentastagiu.homework3.restaurant; + +public class VegetarianRestaurant extends Restaurant implements CalculateTaxes { +} From a5a68adfdee9a0abcae5682755e6ec163eb56151 Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Sun, 22 Dec 2019 09:40:35 +0200 Subject: [PATCH 04/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/restaurant/CalculateTaxes.java | 4 -- .../restaurant/FastFoodRestaurant.java | 15 +++++++ .../homework3/restaurant/MainApp.java | 18 ++++++++ .../homework3/restaurant/Restaurant.java | 43 ++++++++++++++++--- .../restaurant/VegetarianRestaurant.java | 18 +++++++- 5 files changed, 88 insertions(+), 10 deletions(-) delete mode 100644 src/com/pentalog/pentastagiu/homework3/restaurant/CalculateTaxes.java create mode 100644 src/com/pentalog/pentastagiu/homework3/restaurant/FastFoodRestaurant.java create mode 100644 src/com/pentalog/pentastagiu/homework3/restaurant/MainApp.java diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/CalculateTaxes.java b/src/com/pentalog/pentastagiu/homework3/restaurant/CalculateTaxes.java deleted file mode 100644 index 3b2ff43..0000000 --- a/src/com/pentalog/pentastagiu/homework3/restaurant/CalculateTaxes.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.pentalog.pentastagiu.homework3.restaurant; - -public interface CalculateTaxes { -} diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/FastFoodRestaurant.java b/src/com/pentalog/pentastagiu/homework3/restaurant/FastFoodRestaurant.java new file mode 100644 index 0000000..8b35758 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/restaurant/FastFoodRestaurant.java @@ -0,0 +1,15 @@ +package com.pentalog.pentastagiu.homework3.restaurant; + +public class FastFoodRestaurant extends Restaurant { + + + public FastFoodRestaurant(int priceForFixedMenu) { + super(priceForFixedMenu); + } + + @Override + public void calculateIncomeAndTaxes() { + System.out.println("Income are " + (getIncome()*0.8)); + System.out.println("Taxes are " +(getIncome()*0.2)); + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/MainApp.java b/src/com/pentalog/pentastagiu/homework3/restaurant/MainApp.java new file mode 100644 index 0000000..2c343f8 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/restaurant/MainApp.java @@ -0,0 +1,18 @@ +package com.pentalog.pentastagiu.homework3.restaurant; + +public class MainApp { + public static void main(String[] args) { + FastFoodRestaurant fast1=new FastFoodRestaurant(10); + fast1.accommodateGuest(5); + System.out.println("FastFood Restaurant"); + System.out.println(fast1.getTotalNumberOfGuest()); + fast1.calculateIncomeAndTaxes(); + + VegetarianRestaurant veg1=new VegetarianRestaurant(10); + veg1.accommodateGuest(5); + System.out.println("Vegetarian Restaurant"); + System.out.println(veg1.getTotalNumberOfGuest()); + veg1.calculateIncomeAndTaxes(); + + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/Restaurant.java b/src/com/pentalog/pentastagiu/homework3/restaurant/Restaurant.java index 0eed673..0a9d9da 100644 --- a/src/com/pentalog/pentastagiu/homework3/restaurant/Restaurant.java +++ b/src/com/pentalog/pentastagiu/homework3/restaurant/Restaurant.java @@ -1,11 +1,44 @@ package com.pentalog.pentastagiu.homework3.restaurant; -public class Restaurant { - private int numberOfGuest; - private int income; - private int priceForMenu; +public abstract class Restaurant { + private int numberOfGuest = 0; + private int income = 0; + private int priceForFixedMenu; + private int totalNumberOfGuest; - public void acomodateGuest(){ + public int getNumberOfGuest() { + return numberOfGuest; + } + + public void setNumberOfGuest(int numberOfGuest) { + this.numberOfGuest = numberOfGuest; + } + + public int getTotalNumberOfGuest() { + return totalNumberOfGuest; + } + + public int getPriceForFixedMenu() { + return priceForFixedMenu; + } + public void setPriceForFixedMenu(int priceForFixedMenu) { + this.priceForFixedMenu = priceForFixedMenu; } + + public int getIncome() { + return income; + } + + public Restaurant(int priceForFixedMenu) { + this.priceForFixedMenu = priceForFixedMenu; + } + + public void accommodateGuest(int numberOfGuest) { + totalNumberOfGuest = totalNumberOfGuest + numberOfGuest; + income=priceForFixedMenu*totalNumberOfGuest; + } + + public abstract void calculateIncomeAndTaxes(); + } diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/VegetarianRestaurant.java b/src/com/pentalog/pentastagiu/homework3/restaurant/VegetarianRestaurant.java index 1a78ec2..1fff110 100644 --- a/src/com/pentalog/pentastagiu/homework3/restaurant/VegetarianRestaurant.java +++ b/src/com/pentalog/pentastagiu/homework3/restaurant/VegetarianRestaurant.java @@ -1,4 +1,20 @@ package com.pentalog.pentastagiu.homework3.restaurant; -public class VegetarianRestaurant extends Restaurant implements CalculateTaxes { +public class VegetarianRestaurant extends Restaurant { + + + public VegetarianRestaurant(int priceForFixedMenu) { + super(priceForFixedMenu); + } + + @Override + public void calculateIncomeAndTaxes() { + double interIncome=getIncome()*0.8; + double interTaxes=getIncome()*0.2; + double refund =interTaxes*0.3; + double finalIncome=interIncome+refund; + double finalTaxes=interTaxes-refund; + System.out.println("Income are " + finalIncome); + System.out.println("Taxes are " +finalTaxes); + } } From 5c4fec3206279f8660688d42e9458bccbc30a11f Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Sat, 28 Dec 2019 12:05:09 +0200 Subject: [PATCH 05/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/bluetooth/BluetoothAp.java | 47 ++++++++++++++++ .../pentastagiu/homework3/bluetooth/Cars.java | 9 ++++ .../homework3/bluetooth/Connectable.java | 5 ++ .../homework3/bluetooth/Items.java | 8 +++ .../homework3/bluetooth/Phones.java | 7 +++ .../bluetooth/SmartRefigerators.java | 7 +++ .../homework3/bluetooth/Students.java | 5 ++ .../homework3/perimeterAndArea/MainApp.java | 4 ++ .../homework3/restaurant/MainApp.java | 10 ++++ .../homework3/strategyGame/Artifact.java | 19 +++++++ .../homework3/strategyGame/Character.java | 43 +++++++++++++++ .../homework3/strategyGame/Humans.java | 11 ++++ .../homework3/strategyGame/MainApp.java | 25 +++++++++ .../homework3/strategyGame/Monster.java | 9 ++++ .../homework3/strategyGame/positionOnMap.java | 35 ++++++++++++ .../pentastagiu/week3/university/Student.java | 53 ------------------- .../week3/university/UniversityApp.java | 27 ---------- 17 files changed, 244 insertions(+), 80 deletions(-) create mode 100644 src/com/pentalog/pentastagiu/homework3/bluetooth/BluetoothAp.java create mode 100644 src/com/pentalog/pentastagiu/homework3/bluetooth/Cars.java create mode 100644 src/com/pentalog/pentastagiu/homework3/bluetooth/Connectable.java create mode 100644 src/com/pentalog/pentastagiu/homework3/bluetooth/Items.java create mode 100644 src/com/pentalog/pentastagiu/homework3/bluetooth/Phones.java create mode 100644 src/com/pentalog/pentastagiu/homework3/bluetooth/SmartRefigerators.java create mode 100644 src/com/pentalog/pentastagiu/homework3/bluetooth/Students.java create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/positionOnMap.java delete mode 100644 src/com/pentalog/pentastagiu/week3/university/Student.java delete mode 100644 src/com/pentalog/pentastagiu/week3/university/UniversityApp.java diff --git a/src/com/pentalog/pentastagiu/homework3/bluetooth/BluetoothAp.java b/src/com/pentalog/pentastagiu/homework3/bluetooth/BluetoothAp.java new file mode 100644 index 0000000..2f7fee3 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/bluetooth/BluetoothAp.java @@ -0,0 +1,47 @@ + +//Create a console application from the following requirements: +//In the application we will work with few things: cars, phones, smart refrigerators. Add some specific details for each one +//We want each of these things to be able to connect with bluetooth → write a Connectable interface in which you specify this contract: a method called connectToBluetooth +//Add another simple class, Student for example, which doesn’t have to implement the Connectable interface +//Implement this contract in each class that you have and add a specific implementation +// (in which you just print to console a message in which you specify: “Connect to bluetooth in progress...” and the name of +// the device) + + +package com.pentalog.pentastagiu.homework3.bluetooth; + +import java.util.ArrayList; +import java.util.List; + +import static javafx.scene.input.KeyCode.T; + + +public class BluetoothAp { + + + + + public static void main(String[] args) { + Cars car1 = new Cars(); + Phones phone1 = new Phones(); + SmartRefigerators ref1 = new SmartRefigerators(); + Students stud1 = new Students(); + + List objects = new ArrayList<>(); + objects.add(car1); + objects.add(phone1); + objects.add(ref1); + objects.add(stud1); + + for(Object x : objects) { + if (x instanceof Items){ + System.out.println(x.getClass()+ " "+((Items) x).connectToBluetooth()); + } else + { + + System.out.println(x.getClass()+" Unable to connect to bluetooth"); + } + } + + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/bluetooth/Cars.java b/src/com/pentalog/pentastagiu/homework3/bluetooth/Cars.java new file mode 100644 index 0000000..ca133ba --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/bluetooth/Cars.java @@ -0,0 +1,9 @@ +package com.pentalog.pentastagiu.homework3.bluetooth; + +public class Cars extends Items{ + private int EnginePistons; + private int GearsNumbers; + + + +} diff --git a/src/com/pentalog/pentastagiu/homework3/bluetooth/Connectable.java b/src/com/pentalog/pentastagiu/homework3/bluetooth/Connectable.java new file mode 100644 index 0000000..8d4ad13 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/bluetooth/Connectable.java @@ -0,0 +1,5 @@ +package com.pentalog.pentastagiu.homework3.bluetooth; + +public interface Connectable { + public String connectToBluetooth(); +} diff --git a/src/com/pentalog/pentastagiu/homework3/bluetooth/Items.java b/src/com/pentalog/pentastagiu/homework3/bluetooth/Items.java new file mode 100644 index 0000000..3df10fa --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/bluetooth/Items.java @@ -0,0 +1,8 @@ +package com.pentalog.pentastagiu.homework3.bluetooth; + +public class Items implements Connectable { + @Override + public String connectToBluetooth() { + return ("Connect to bluetooth in progress..."); + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/bluetooth/Phones.java b/src/com/pentalog/pentastagiu/homework3/bluetooth/Phones.java new file mode 100644 index 0000000..2a6e6e7 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/bluetooth/Phones.java @@ -0,0 +1,7 @@ +package com.pentalog.pentastagiu.homework3.bluetooth; + +public class Phones extends Items{ + private String Os; + + +} diff --git a/src/com/pentalog/pentastagiu/homework3/bluetooth/SmartRefigerators.java b/src/com/pentalog/pentastagiu/homework3/bluetooth/SmartRefigerators.java new file mode 100644 index 0000000..80f1e36 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/bluetooth/SmartRefigerators.java @@ -0,0 +1,7 @@ +package com.pentalog.pentastagiu.homework3.bluetooth; + +public class SmartRefigerators extends Items{ + private int Capacity; + + +} diff --git a/src/com/pentalog/pentastagiu/homework3/bluetooth/Students.java b/src/com/pentalog/pentastagiu/homework3/bluetooth/Students.java new file mode 100644 index 0000000..a6fdaa6 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/bluetooth/Students.java @@ -0,0 +1,5 @@ +package com.pentalog.pentastagiu.homework3.bluetooth; + +public class Students { + private String name; +} diff --git a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/MainApp.java b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/MainApp.java index 7dda605..6fd5f4d 100644 --- a/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/MainApp.java +++ b/src/com/pentalog/pentastagiu/homework3/perimeterAndArea/MainApp.java @@ -1,3 +1,7 @@ + +//Create an application that knows how to calculate the perimeter and area for common shapes(circle, square, rectangle, triangle) +//To test it: create few objects of each type and print to the console information about the object that has the biggest area + package com.pentalog.pentastagiu.homework3.perimeterAndArea; import com.sun.deploy.security.WinDeployNTLMAuthCallback; diff --git a/src/com/pentalog/pentastagiu/homework3/restaurant/MainApp.java b/src/com/pentalog/pentastagiu/homework3/restaurant/MainApp.java index 2c343f8..82616a5 100644 --- a/src/com/pentalog/pentastagiu/homework3/restaurant/MainApp.java +++ b/src/com/pentalog/pentastagiu/homework3/restaurant/MainApp.java @@ -1,3 +1,13 @@ + +//Create a console application that works with restaurants +//Each restaurant will have info about the current number of guests, the income, the price for a fixed menu +//Each restaurant will have a method that accommodates new guest in which the number of current guests has to increase with the number of new guests and the income also will increase accordingly(each new guest will consume a fixed price menu). +//We will also have the option of calculating the taxes that each restaurant has to pay to the local authorities, but each restaurant will have a different way of calculating this +//Let's consider that we will have 2 types of restaurants: vegetarian restaurant and fast food restaurant. +// Each restaurant will have to pay taxes to the local authorities, which represent 20% of their income. Also the local authorities from the town where we have restaurants, +// that want to encourage a healthy life, decided that the vegetarian restaurant will receive a discount of 30% for the taxation. +//Implement for each restaurant a method that calculates the tax that it has to pay. + package com.pentalog.pentastagiu.homework3.restaurant; public class MainApp { diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java new file mode 100644 index 0000000..b3b8033 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java @@ -0,0 +1,19 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class Artifact extends positionOnMap{ + + private int extraPoints; + + public Artifact(int x, int y, int extraPoints) { + super(x, y); + this.extraPoints = extraPoints; + } + + public int getExtraPoints() { + return extraPoints; + } + + public void setExtraPoints(int extraPoints) { + this.extraPoints = extraPoints; + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java new file mode 100644 index 0000000..24ddc69 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -0,0 +1,43 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class Character extends positionOnMap { + private String name; + private int healthPoints, energyPoints; + + public Character(int x, int y, String name, int healthPoints, int energyPoints) { + super(x, y); + + this.healthPoints = healthPoints; + this.energyPoints = energyPoints; + + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getHealthPoints() { + return healthPoints; + } + + public void setHealthPoints(int healthPoints) { + this.healthPoints = healthPoints; + } + + public int getEnergyPoints() { + return energyPoints; + } + + public void setEnergyPoints(int energyPoints) { + this.energyPoints = energyPoints; + } + + public void receiveArtifact(){ + + } + +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java new file mode 100644 index 0000000..f126510 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java @@ -0,0 +1,11 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class Humans extends Character { + private String type; + public Humans(int x, int y, String name, int healthPoints, int energyPoints) { + super(x, y, name, healthPoints, energyPoints); + type="human"; + System.out.println(type+" was created with name "+name +" "+ healthPoints + " healthPoints "+energyPoints+" energyPoints"); + getPositionOnMap(); + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java new file mode 100644 index 0000000..e7ab328 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java @@ -0,0 +1,25 @@ +//Create a console application from the following requirements: +//We plan to create a strategy game: in this game we will have characters and artifacts +//Each artifact will have a position on the map(x and y) and a number of extra points. We will have 2 types of artifacts: health artifact and energy artifact +//Each character can be a human, a monster or an animal; each one will have a name, a number of health points, a number of energy points and a position on the +// map (x and y); for each one we will have the method that gives us the position on the map and also a method that will receive as parameter an artifact and +// will increase the number of health points or energy points of the character with the number of extra points given by the artifact, depending on the type of artifact that is passed as parameter +//Some of the characters will have the ability of attacking other characters: +//Humans can attack: in which case they will waste 5 energy points and the character that is attacked will lose 10 health points +//Monsters can attack: in which case they will lose 3 energy points and the character that is attacked will lose 15 +//Use a scenario in which you create few artifacts, few characters(one of each type), play with the objects from the game and display at the end the status for each characters +//For extra functionality, you can add validation logic(for example if someone attacks a character that doesn’t have enough health points a message is displayed that the character attacked is +// already dead) or logic related to the position on the map(you will consider a 10 per 10 map and when attacking a character, verify first the distance of the current character to the attacker +// it’s smaller than 5 and only in that case initiate the attack) + + +package com.pentalog.pentastagiu.homework3.strategyGame; + + + +public class MainApp { + public static void main(String[] args) { +Humans om=new Humans(0,0,"cavaler", 10,20); + + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java new file mode 100644 index 0000000..2a09b7c --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java @@ -0,0 +1,9 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class Monster extends Character { + private String type; + public Monster(int x, int y, String name, int healthPoints, int energyPoints, String type) { + super(x, y, name, healthPoints, energyPoints); + type="monster"; + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/positionOnMap.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/positionOnMap.java new file mode 100644 index 0000000..c76870a --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/positionOnMap.java @@ -0,0 +1,35 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +import java.util.HashMap; +import java.util.Map; + +public class positionOnMap { + + private int x,y; + + public positionOnMap() { + this(0,0); + } + public positionOnMap(int x, int y) { + this.x = x; + this.y = y; + } + public int getx() { + return x; + } + public int gety() { + return y; + } + public void setx(int x) { + this.x = x; + } + public void sety(int y) { + this.y = y; + } + + public void getPositionOnMap(){ + + System.out.println(getx() +" : "+gety()); + } + +} diff --git a/src/com/pentalog/pentastagiu/week3/university/Student.java b/src/com/pentalog/pentastagiu/week3/university/Student.java deleted file mode 100644 index 5efab01..0000000 --- a/src/com/pentalog/pentastagiu/week3/university/Student.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.pentalog.pentastagiu.week3.university; - -public class Student { - private String firstName; - private String lastName; - private double grade; - private boolean active = true; - - public double getGrade() { - return grade; - } - - public void setGrade(double grade) { - if (grade < 1 || grade > 10) { - System.out.println("warning: not a valid grade!"); - return; - } - - this.grade = grade; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public boolean isActive() { - return active; - } - - public void setActive(boolean active) { - this.active = active; - } - - public boolean hasScholarship() { - return grade > 7.5; - } - - void printStudentInfoToConsole() { - System.out.println("Student " + firstName.toUpperCase() + " " + this.lastName + " is active: " + active + ", grade: " + grade); - } -} diff --git a/src/com/pentalog/pentastagiu/week3/university/UniversityApp.java b/src/com/pentalog/pentastagiu/week3/university/UniversityApp.java deleted file mode 100644 index 9c3c7db..0000000 --- a/src/com/pentalog/pentastagiu/week3/university/UniversityApp.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.pentalog.pentastagiu.week3.university; - -public class UniversityApp { - - public static void main(String[] args) { - //buildStudentsWithoutOOP(); - - Student student = new Student(); - student.setFirstName("Andrei"); - student.setLastName("Popescu"); - student.setGrade(-1); - student.printStudentInfoToConsole(); - } - - private static void buildStudentsWithoutOOP() { - String firstName = "Andrei"; - String lastName = "Popescu"; - double grade = 6.5; - System.out.println("Student " + firstName + " " + lastName + " has grade " + grade); - - String firstNameStudent2 = "Maria"; - String lastNameStudent2 = "Ionescu"; - double gradeStudent2 = 6; - System.out.println("Student " + firstNameStudent2 + " " + lastNameStudent2 + " has grade " + gradeStudent2); - } - -} From 9d197332d13a792d03bf775bb88cc77a6862448b Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Wed, 1 Jan 2020 18:11:25 +0200 Subject: [PATCH 06/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/strategyGame/Artifact.java | 16 ++----- .../homework3/strategyGame/Character.java | 39 ++-------------- .../strategyGame/HealthArtifact.java | 8 ++++ .../homework3/strategyGame/Humans.java | 11 ----- .../homework3/strategyGame/Items.java | 45 +++++++++++++++++++ .../homework3/strategyGame/MainApp.java | 15 ++++++- .../homework3/strategyGame/Monster.java | 7 +-- .../homework3/strategyGame/positionOnMap.java | 35 --------------- 8 files changed, 77 insertions(+), 99 deletions(-) create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/HealthArtifact.java delete mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java delete mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/positionOnMap.java diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java index b3b8033..492be43 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java @@ -1,19 +1,11 @@ package com.pentalog.pentastagiu.homework3.strategyGame; -public class Artifact extends positionOnMap{ +import java.util.Random; - private int extraPoints; +public class Artifact extends Items { - public Artifact(int x, int y, int extraPoints) { - super(x, y); - this.extraPoints = extraPoints; - } - - public int getExtraPoints() { - return extraPoints; - } - public void setExtraPoints(int extraPoints) { - this.extraPoints = extraPoints; + public Artifact(int x, int y, int healthPoint, int energyPoint) { + super(x, y, healthPoint, energyPoint); } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index 24ddc69..08711ab 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -1,43 +1,12 @@ package com.pentalog.pentastagiu.homework3.strategyGame; -public class Character extends positionOnMap { - private String name; - private int healthPoints, energyPoints; - - public Character(int x, int y, String name, int healthPoints, int energyPoints) { - super(x, y); +public class Character extends Items { - this.healthPoints = healthPoints; - this.energyPoints = energyPoints; - } - - public String getName() { - return name; - } + private String name; - public void setName(String name) { + public Character(int x, int y, int healthPoint, int energyPoint, String name) { + super(x, y, healthPoint, energyPoint); this.name = name; } - - public int getHealthPoints() { - return healthPoints; - } - - public void setHealthPoints(int healthPoints) { - this.healthPoints = healthPoints; - } - - public int getEnergyPoints() { - return energyPoints; - } - - public void setEnergyPoints(int energyPoints) { - this.energyPoints = energyPoints; - } - - public void receiveArtifact(){ - - } - } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/HealthArtifact.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/HealthArtifact.java new file mode 100644 index 0000000..16dab29 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/HealthArtifact.java @@ -0,0 +1,8 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class HealthArtifact extends Artifact { + + public HealthArtifact(int x, int y, int healthPoint, int energyPoint) { + super(x, y, healthPoint, energyPoint=0); + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java deleted file mode 100644 index f126510..0000000 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.pentalog.pentastagiu.homework3.strategyGame; - -public class Humans extends Character { - private String type; - public Humans(int x, int y, String name, int healthPoints, int energyPoints) { - super(x, y, name, healthPoints, energyPoints); - type="human"; - System.out.println(type+" was created with name "+name +" "+ healthPoints + " healthPoints "+energyPoints+" energyPoints"); - getPositionOnMap(); - } -} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java new file mode 100644 index 0000000..40586e7 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java @@ -0,0 +1,45 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class Items { + + private int x,y,healthPoint,energyPoint; + + public Items(int x, int y, int healthPoint, int energyPoint) { + this.x = x; + this.y = y; + this.healthPoint = healthPoint; + this.energyPoint = energyPoint; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + + public int getHealthPoint() { + return healthPoint; + } + + public void setHealthPoint(int healthPoint) { + this.healthPoint = healthPoint; + } + + public int getEnergyPoint() { + return energyPoint; + } + + public void setEnergyPoint(int energyPoint) { + this.energyPoint = energyPoint; + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java index e7ab328..c2a5f7c 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java @@ -18,8 +18,21 @@ public class MainApp { + + public static void calculateDistance (Items items1, Items items2){ + + double dis2; + + dis2=Math.sqrt((items2.getX()-items1.getX())*((items2.getX()-items1.getX()) + (items2.getY()-items1.getY())*(items2.getY()-items1.getY()))); + System.out.println("distancebetween"+"("+items1.getX()+","+items1.getY()+"),"+"("+items2.getX()+","+items2.getY()+")===>"+dis2); + + } + public static void main(String[] args) { -Humans om=new Humans(0,0,"cavaler", 10,20); + Items human1=new Items(3,3,10,15); + Items monster=new Items(4,4,12,23); + calculateDistance(human1,monster); + } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java index 2a09b7c..9bea716 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java @@ -1,9 +1,6 @@ package com.pentalog.pentastagiu.homework3.strategyGame; -public class Monster extends Character { +public class Monster { private String type; - public Monster(int x, int y, String name, int healthPoints, int energyPoints, String type) { - super(x, y, name, healthPoints, energyPoints); - type="monster"; - } + } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/positionOnMap.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/positionOnMap.java deleted file mode 100644 index c76870a..0000000 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/positionOnMap.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.pentalog.pentastagiu.homework3.strategyGame; - -import java.util.HashMap; -import java.util.Map; - -public class positionOnMap { - - private int x,y; - - public positionOnMap() { - this(0,0); - } - public positionOnMap(int x, int y) { - this.x = x; - this.y = y; - } - public int getx() { - return x; - } - public int gety() { - return y; - } - public void setx(int x) { - this.x = x; - } - public void sety(int y) { - this.y = y; - } - - public void getPositionOnMap(){ - - System.out.println(getx() +" : "+gety()); - } - -} From 318eb297591a8a543548ab798432875062ac41f6 Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Fri, 3 Jan 2020 07:46:00 +0200 Subject: [PATCH 07/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/strategyGame/Artifact.java | 6 ++- .../homework3/strategyGame/Character.java | 45 ++++++++++++++++++- .../strategyGame/EnergyArtifact.java | 19 ++++++++ .../strategyGame/HealthArtifact.java | 15 ++++++- .../homework3/strategyGame/Humans.java | 12 +++++ .../homework3/strategyGame/Items.java | 21 ++------- .../homework3/strategyGame/MainApp.java | 9 ++-- .../homework3/strategyGame/Monster.java | 11 ++++- 8 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/EnergyArtifact.java create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java index 492be43..5392e23 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java @@ -5,7 +5,9 @@ public class Artifact extends Items { - public Artifact(int x, int y, int healthPoint, int energyPoint) { - super(x, y, healthPoint, energyPoint); + + public Artifact(int x, int y) { + super(x, y); + } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index 08711ab..67815d6 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -4,9 +4,50 @@ public class Character extends Items { private String name; + private int energyPoints, healthPoints; - public Character(int x, int y, int healthPoint, int energyPoint, String name) { - super(x, y, healthPoint, energyPoint); + public Character(int x, int y, String name, int energyPoints, int healthPoints) { + super(x, y); this.name = name; + this.energyPoints = energyPoints; + this.healthPoints = healthPoints; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getEnergyPoints() { + return energyPoints; + } + + public void setEnergyPoints(int energyPoints) { + this.energyPoints = energyPoints; + } + + public int getHealthPoints() { + return healthPoints; + } + + public void setHealthPoints(int healthPoints) { + this.healthPoints = healthPoints; + } + + public void positionOnMap(){ + System.out.println("Current position:" + getX()+" "+getY()); + } + + public void acquireArtifact(Artifact artifact){ + if (artifact instanceof EnergyArtifact){ + energyPoints=+((EnergyArtifact) artifact).getEnergyPoint(); + + } else if (artifact instanceof HealthArtifact){ + + healthPoints=+((HealthArtifact) artifact).getHealthPoint(); + } } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/EnergyArtifact.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/EnergyArtifact.java new file mode 100644 index 0000000..9420346 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/EnergyArtifact.java @@ -0,0 +1,19 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class EnergyArtifact extends Artifact { + + int energyPoint; + + public EnergyArtifact(int x, int y, int energyPointPoint) { + super(x, y); + this.energyPoint = energyPointPoint; + } + + public int getEnergyPoint() { + return energyPoint; + } + + public void setEnergyPoint(int energyPoint) { + this.energyPoint = energyPoint; + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/HealthArtifact.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/HealthArtifact.java index 16dab29..7196d81 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/HealthArtifact.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/HealthArtifact.java @@ -2,7 +2,18 @@ public class HealthArtifact extends Artifact { - public HealthArtifact(int x, int y, int healthPoint, int energyPoint) { - super(x, y, healthPoint, energyPoint=0); + int healthPoint; + + public HealthArtifact(int x, int y, int healthPoint) { + super(x, y); + this.healthPoint = healthPoint; + } + + public int getHealthPoint() { + return healthPoint; + } + + public void setHealthPoint(int healthPoint) { + this.healthPoint = healthPoint; } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java new file mode 100644 index 0000000..bf3810f --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java @@ -0,0 +1,12 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class Humans extends Character { + public Humans(int x, int y, String name, int energyPoints, int healthPoints) { + super(x, y, name, energyPoints, healthPoints); + } + + private void Attack(Monster monster){ + + } + +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java index 40586e7..ca87f6f 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java @@ -2,13 +2,12 @@ public class Items { - private int x,y,healthPoint,energyPoint; + private int x,y; - public Items(int x, int y, int healthPoint, int energyPoint) { + public Items(int x, int y) { this.x = x; this.y = y; - this.healthPoint = healthPoint; - this.energyPoint = energyPoint; + } public int getX() { @@ -27,19 +26,5 @@ public void setY(int y) { this.y = y; } - public int getHealthPoint() { - return healthPoint; - } - - public void setHealthPoint(int healthPoint) { - this.healthPoint = healthPoint; - } - public int getEnergyPoint() { - return energyPoint; - } - - public void setEnergyPoint(int energyPoint) { - this.energyPoint = energyPoint; - } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java index c2a5f7c..d53ae9f 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java @@ -29,9 +29,12 @@ public static void calculateDistance (Items items1, Items items2){ } public static void main(String[] args) { - Items human1=new Items(3,3,10,15); - Items monster=new Items(4,4,12,23); - calculateDistance(human1,monster); + Humans h1=new Humans(2,4,"pov",20,12); + Monster m1=new Monster(3,2,"fraier",23,11); + + calculateDistance(h1,m1); + + } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java index 9bea716..5a21dcd 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java @@ -1,6 +1,13 @@ package com.pentalog.pentastagiu.homework3.strategyGame; -public class Monster { - private String type; +public class Monster extends Character { + + public Monster(int x, int y, String name, int energyPoints, int healthPoints) { + super(x, y, name, energyPoints, healthPoints); + } + + private void Attack(Humans humans){ + + } } From 1075ef6744ac8fe566dc95109a8d5adaa28085f5 Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Sat, 4 Jan 2020 11:45:55 +0200 Subject: [PATCH 08/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/strategyGame/Character.java | 12 +++++++----- .../pentastagiu/homework3/strategyGame/Humans.java | 2 -- .../pentastagiu/homework3/strategyGame/MainApp.java | 12 ++++++++---- .../pentastagiu/homework3/strategyGame/Monster.java | 2 -- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index 67815d6..f3ed950 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -37,17 +37,19 @@ public void setHealthPoints(int healthPoints) { this.healthPoints = healthPoints; } - public void positionOnMap(){ - System.out.println("Current position:" + getX()+" "+getY()); - } + public void acquireArtifact(Artifact artifact){ if (artifact instanceof EnergyArtifact){ - energyPoints=+((EnergyArtifact) artifact).getEnergyPoint(); + energyPoints=energyPoints+((EnergyArtifact) artifact).getEnergyPoint(); } else if (artifact instanceof HealthArtifact){ - healthPoints=+((HealthArtifact) artifact).getHealthPoint(); + healthPoints=healthPoints+((HealthArtifact) artifact).getHealthPoint(); } } + + public void curentStatus(){ + System.out.println("Current position:" + getX()+" "+getY() + " health "+healthPoints + " energy "+energyPoints); + } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java index bf3810f..e19fe81 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java @@ -5,8 +5,6 @@ public Humans(int x, int y, String name, int energyPoints, int healthPoints) { super(x, y, name, energyPoints, healthPoints); } - private void Attack(Monster monster){ - } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java index d53ae9f..60975a3 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java @@ -24,18 +24,22 @@ public static void calculateDistance (Items items1, Items items2){ double dis2; dis2=Math.sqrt((items2.getX()-items1.getX())*((items2.getX()-items1.getX()) + (items2.getY()-items1.getY())*(items2.getY()-items1.getY()))); - System.out.println("distancebetween"+"("+items1.getX()+","+items1.getY()+"),"+"("+items2.getX()+","+items2.getY()+")===>"+dis2); + System.out.println("distance between"+"("+items1.getX()+","+items1.getY()+"),"+"("+items2.getX()+","+items2.getY()+")===>"+dis2); } public static void main(String[] args) { Humans h1=new Humans(2,4,"pov",20,12); Monster m1=new Monster(3,2,"fraier",23,11); + HealthArtifact healthArtifact=new HealthArtifact(2,3,25); + EnergyArtifact energyArtifact=new EnergyArtifact(4,2,12); calculateDistance(h1,m1); - - - +h1.curentStatus(); +h1.acquireArtifact(healthArtifact); +h1.curentStatus(); +h1.acquireArtifact(energyArtifact); +h1.curentStatus(); } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java index 5a21dcd..e388e84 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java @@ -7,7 +7,5 @@ public Monster(int x, int y, String name, int energyPoints, int healthPoints) { super(x, y, name, energyPoints, healthPoints); } - private void Attack(Humans humans){ - } } From d3fd85673a63a4e4e61e0920e4e7d0d291a3a89a Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Mon, 6 Jan 2020 07:10:34 +0200 Subject: [PATCH 09/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/strategyGame/Character.java | 52 ++++++++++++++++--- .../homework3/strategyGame/Humans.java | 7 ++- .../homework3/strategyGame/Items.java | 10 +++- .../homework3/strategyGame/MainApp.java | 37 ++++++------- .../homework3/strategyGame/Monster.java | 4 +- 5 files changed, 77 insertions(+), 33 deletions(-) diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index f3ed950..6499b4a 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -3,8 +3,21 @@ public class Character extends Items { +// private static double dis2; private String name; - private int energyPoints, healthPoints; + private int energyPoints; + private int healthPoints; + + public int getAtackForce() { + return atackForce; + } + + public void setAtackForce(int atackForce) { + this.atackForce = atackForce; + } + + private int atackForce; + public Character(int x, int y, String name, int energyPoints, int healthPoints) { super(x, y); @@ -38,18 +51,41 @@ public void setHealthPoints(int healthPoints) { } + public void acquireArtifact(Artifact artifact) { + if (artifact instanceof EnergyArtifact) { + energyPoints = energyPoints + ((EnergyArtifact) artifact).getEnergyPoint(); - public void acquireArtifact(Artifact artifact){ - if (artifact instanceof EnergyArtifact){ - energyPoints=energyPoints+((EnergyArtifact) artifact).getEnergyPoint(); + } else if (artifact instanceof HealthArtifact) { - } else if (artifact instanceof HealthArtifact){ + healthPoints = healthPoints + ((HealthArtifact) artifact).getHealthPoint(); + } + } - healthPoints=healthPoints+((HealthArtifact) artifact).getHealthPoint(); + public static double calculateDistance(Items items1, Items items2) { + + double dis2; + + dis2 = Math.sqrt((items2.getX() - items1.getX()) * ((items2.getX() - items1.getX()) + (items2.getY() - items1.getY()) * (items2.getY() - items1.getY()))); + System.out.println("distance between" + "(" + items1.getX() + "," + items1.getY() + ")," + "(" + items2.getX() + "," + items2.getY() + ")===>" + dis2); + return dis2; + + } + + public static void attack(Character attacker, Character target) { + if (calculateDistance(attacker,target) < 5 && target.healthPoints"+dis2); - - } public static void main(String[] args) { - Humans h1=new Humans(2,4,"pov",20,12); - Monster m1=new Monster(3,2,"fraier",23,11); - HealthArtifact healthArtifact=new HealthArtifact(2,3,25); - EnergyArtifact energyArtifact=new EnergyArtifact(4,2,12); - - calculateDistance(h1,m1); -h1.curentStatus(); -h1.acquireArtifact(healthArtifact); -h1.curentStatus(); -h1.acquireArtifact(energyArtifact); -h1.curentStatus(); - + Humans h1 = new Humans(2,3,"human",12,19,10); + Monster m1 = new Monster(3, 2, "monstru", 23, 9,15); + HealthArtifact healthArtifact = new HealthArtifact(2, 3, 25); + EnergyArtifact energyArtifact = new EnergyArtifact(4, 2, 12); + + + h1.curentStatus(); + h1.acquireArtifact(healthArtifact); + h1.curentStatus(); + h1.acquireArtifact(energyArtifact); + h1.curentStatus(); + m1.curentStatus(); + Character.calculateDistance(h1, m1); + attack(h1, m1); + h1.curentStatus(); + m1.curentStatus(); } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java index e388e84..bbde598 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java @@ -3,8 +3,10 @@ public class Monster extends Character { - public Monster(int x, int y, String name, int energyPoints, int healthPoints) { + + public Monster(int x, int y, String name, int energyPoints, int healthPoints, int atacForce) { super(x, y, name, energyPoints, healthPoints); + atacForce=15; } From ddb75570d939146c827c1b6a93eaac011089cd55 Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Mon, 6 Jan 2020 07:56:53 +0200 Subject: [PATCH 10/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../pentastagiu/homework3/strategyGame/Character.java | 4 ++-- .../pentastagiu/homework3/strategyGame/MainApp.java | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index 6499b4a..1ec63c9 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -72,14 +72,14 @@ public static double calculateDistance(Items items1, Items items2) { } public static void attack(Character attacker, Character target) { - if (calculateDistance(attacker,target) < 5 && target.healthPoints Date: Mon, 6 Jan 2020 09:01:19 +0200 Subject: [PATCH 11/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/strategyGame/Character.java | 18 ++++++------------ .../homework3/strategyGame/MainApp.java | 6 +++--- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index 1ec63c9..6e37447 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -3,20 +3,13 @@ public class Character extends Items { -// private static double dis2; + // private static double dis2; + private int atackForce; private String name; private int energyPoints; private int healthPoints; - public int getAtackForce() { - return atackForce; - } - - public void setAtackForce(int atackForce) { - this.atackForce = atackForce; - } - private int atackForce; public Character(int x, int y, String name, int energyPoints, int healthPoints) { @@ -69,22 +62,23 @@ public static double calculateDistance(Items items1, Items items2) { System.out.println("distance between" + "(" + items1.getX() + "," + items1.getY() + ")," + "(" + items2.getX() + "," + items2.getY() + ")===>" + dis2); return dis2; + } public static void attack(Character attacker, Character target) { -// if (calculateDistance(attacker,target) < 5 && target.healthPoints Date: Wed, 8 Jan 2020 09:34:13 +0200 Subject: [PATCH 12/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/strategyGame/Character.java | 21 ++++++++++++------- .../homework3/strategyGame/Humans.java | 8 +++---- .../homework3/strategyGame/Items.java | 6 +++++- .../homework3/strategyGame/MainApp.java | 4 ++-- .../homework3/strategyGame/Monster.java | 8 ++----- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index 6e37447..6af0bd5 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -10,10 +10,9 @@ public class Character extends Items { private int healthPoints; - - - public Character(int x, int y, String name, int energyPoints, int healthPoints) { + public Character(int x, int y, int atackForce, String name, int energyPoints, int healthPoints) { super(x, y); + this.atackForce = atackForce; this.name = name; this.energyPoints = energyPoints; this.healthPoints = healthPoints; @@ -47,11 +46,13 @@ public void setHealthPoints(int healthPoints) { public void acquireArtifact(Artifact artifact) { if (artifact instanceof EnergyArtifact) { energyPoints = energyPoints + ((EnergyArtifact) artifact).getEnergyPoint(); - + System.out.println("Energy artifact taken " +((EnergyArtifact) artifact).energyPoint); } else if (artifact instanceof HealthArtifact) { - + System.out.println("Health artifact taken " +((HealthArtifact) artifact).healthPoint); healthPoints = healthPoints + ((HealthArtifact) artifact).getHealthPoint(); } + + } public static double calculateDistance(Items items1, Items items2) { @@ -60,19 +61,23 @@ public static double calculateDistance(Items items1, Items items2) { dis2 = Math.sqrt((items2.getX() - items1.getX()) * ((items2.getX() - items1.getX()) + (items2.getY() - items1.getY()) * (items2.getY() - items1.getY()))); System.out.println("distance between" + "(" + items1.getX() + "," + items1.getY() + ")," + "(" + items2.getX() + "," + items2.getY() + ")===>" + dis2); + if (Double.isNaN(dis2)) { + dis2 = 6.0; + } return dis2; } public static void attack(Character attacker, Character target) { - if (calculateDistance(attacker, target) < 5 ) { + if (calculateDistance(attacker, target) < 5 && attacker.atackForce Date: Wed, 8 Jan 2020 16:31:38 +0200 Subject: [PATCH 13/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../pentastagiu/homework3/strategyGame/Character.java | 3 ++- .../pentastagiu/homework3/strategyGame/Humans.java | 7 ++----- .../pentalog/pentastagiu/homework3/strategyGame/Items.java | 6 ++---- .../pentastagiu/homework3/strategyGame/MainApp.java | 4 ++-- .../pentastagiu/homework3/strategyGame/Monster.java | 4 ++-- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index 6af0bd5..138f65b 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -60,10 +60,11 @@ public static double calculateDistance(Items items1, Items items2) { double dis2; dis2 = Math.sqrt((items2.getX() - items1.getX()) * ((items2.getX() - items1.getX()) + (items2.getY() - items1.getY()) * (items2.getY() - items1.getY()))); - System.out.println("distance between" + "(" + items1.getX() + "," + items1.getY() + ")," + "(" + items2.getX() + "," + items2.getY() + ")===>" + dis2); if (Double.isNaN(dis2)) { dis2 = 6.0; } + System.out.println("distance between" + "(" + items1.getX() + "," + items1.getY() + ")," + "(" + items2.getX() + "," + items2.getY() + ")===>" + dis2); + return dis2; diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java index 8a22626..52758a3 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Humans.java @@ -2,10 +2,7 @@ public class Humans extends Character { - - - public Humans(int x, int y, int atackForce, String name, int energyPoints, int healthPoints) { - super(x, y, atackForce, name, energyPoints, healthPoints); - + public Humans(int x, int y, String name, int energyPoints, int healthPoints) { + super(x, y, 10, name, energyPoints, healthPoints); } } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java index b5a614a..e44e3e9 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Items.java @@ -7,8 +7,8 @@ public class Items { private int x,y; public Items(int x, int y) { - this.x = x; - this.y = y; + this.x = (0 < x && x < 10 ? x : 10); + this.y = (0 < y && y < 10 ? y : 10); } @@ -19,9 +19,7 @@ public int getX() { } public void setX(int x) { - this.x=x; - } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java index bd24b5a..8aa90d0 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/MainApp.java @@ -22,8 +22,8 @@ public class MainApp { public static void main(String[] args) { - Humans h1 = new Humans(11,5,10,"human1",19,10); - Monster m1 = new Monster(4, 2, 10, "monster1", 12,20); + Humans h1 = new Humans(5,5,"human1",19,20); + Monster m1 = new Monster(4, 5, "monster1", 12,20); HealthArtifact healthArtifact = new HealthArtifact(2, 3, 25); EnergyArtifact energyArtifact = new EnergyArtifact(4, 2, 12); diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java index cd0b109..6505e5f 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Monster.java @@ -2,8 +2,8 @@ public class Monster extends Character { - public Monster(int x, int y, int atackForce, String name, int energyPoints, int healthPoints) { - super(x, y, atackForce, name, energyPoints, healthPoints); + public Monster(int x, int y, String name, int energyPoints, int healthPoints) { + super(x, y, 15, name, energyPoints, healthPoints); } } From 80046dc930cf92ca28ddb49f803537f079b704bb Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Wed, 8 Jan 2020 16:42:42 +0200 Subject: [PATCH 14/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../homework3/strategyGame/Artifact.java | 6 ++--- .../homework3/strategyGame/Character.java | 27 +++---------------- .../homework3/strategyGame/Items.java | 10 ------- 3 files changed, 6 insertions(+), 37 deletions(-) diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java index 5392e23..07a8256 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java @@ -1,12 +1,10 @@ package com.pentalog.pentastagiu.homework3.strategyGame; -import java.util.Random; - -public class Artifact extends Items { +public class Artifact extends Items { - public Artifact(int x, int y) { + public Artifact(int x, int y) { super(x, y); } diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java index 138f65b..6031953 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Character.java @@ -2,14 +2,12 @@ public class Character extends Items { - // private static double dis2; private int atackForce; private String name; private int energyPoints; private int healthPoints; - public Character(int x, int y, int atackForce, String name, int energyPoints, int healthPoints) { super(x, y); this.atackForce = atackForce; @@ -26,29 +24,12 @@ public void setName(String name) { this.name = name; } - public int getEnergyPoints() { - return energyPoints; - } - - public void setEnergyPoints(int energyPoints) { - this.energyPoints = energyPoints; - } - - public int getHealthPoints() { - return healthPoints; - } - - public void setHealthPoints(int healthPoints) { - this.healthPoints = healthPoints; - } - - public void acquireArtifact(Artifact artifact) { if (artifact instanceof EnergyArtifact) { energyPoints = energyPoints + ((EnergyArtifact) artifact).getEnergyPoint(); - System.out.println("Energy artifact taken " +((EnergyArtifact) artifact).energyPoint); + System.out.println("Energy artifact taken " + ((EnergyArtifact) artifact).energyPoint); } else if (artifact instanceof HealthArtifact) { - System.out.println("Health artifact taken " +((HealthArtifact) artifact).healthPoint); + System.out.println("Health artifact taken " + ((HealthArtifact) artifact).healthPoint); healthPoints = healthPoints + ((HealthArtifact) artifact).getHealthPoint(); } @@ -71,8 +52,8 @@ public static double calculateDistance(Items items1, Items items2) { } public static void attack(Character attacker, Character target) { - if (calculateDistance(attacker, target) < 5 && attacker.atackForce Date: Wed, 8 Jan 2020 16:46:17 +0200 Subject: [PATCH 15/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../pentastagiu/homework3/strategyGame/Animal.java | 7 +++++++ .../pentastagiu/homework3/strategyGame/Artifact.java | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/com/pentalog/pentastagiu/homework3/strategyGame/Animal.java diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Animal.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Animal.java new file mode 100644 index 0000000..f897ff8 --- /dev/null +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Animal.java @@ -0,0 +1,7 @@ +package com.pentalog.pentastagiu.homework3.strategyGame; + +public class Animal extends Character { + public Animal(int x, int y, String name, int energyPoints, int healthPoints) { + super(x, y, 0, name, energyPoints, healthPoints); + } +} diff --git a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java index 07a8256..b30dbae 100644 --- a/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java +++ b/src/com/pentalog/pentastagiu/homework3/strategyGame/Artifact.java @@ -1,7 +1,5 @@ package com.pentalog.pentastagiu.homework3.strategyGame; - - public class Artifact extends Items { public Artifact(int x, int y) { From 5c3b19cdf7e1ac12ec19841a07b0cd792a6d124c Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Mon, 13 Jan 2020 14:55:57 +0200 Subject: [PATCH 16/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- src/{ => homework4}/Homework1.java | 2 ++ src/homework4/circlelist/Circle.java | 13 +++++++++ src/homework4/circlelist/MainApp.java | 38 +++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) rename src/{ => homework4}/Homework1.java (99%) create mode 100644 src/homework4/circlelist/Circle.java create mode 100644 src/homework4/circlelist/MainApp.java diff --git a/src/Homework1.java b/src/homework4/Homework1.java similarity index 99% rename from src/Homework1.java rename to src/homework4/Homework1.java index 427b383..990e5c3 100644 --- a/src/Homework1.java +++ b/src/homework4/Homework1.java @@ -1,3 +1,5 @@ +package homework4; + public class Homework1 { public static void main(String[] args) { diff --git a/src/homework4/circlelist/Circle.java b/src/homework4/circlelist/Circle.java new file mode 100644 index 0000000..d2e7a46 --- /dev/null +++ b/src/homework4/circlelist/Circle.java @@ -0,0 +1,13 @@ +package homework4.circlelist; + +public class Circle { + public double radius; + + public double getRadius() { + return radius; + } + + public void setRadius(double radius) { + this.radius = radius; + } +} diff --git a/src/homework4/circlelist/MainApp.java b/src/homework4/circlelist/MainApp.java new file mode 100644 index 0000000..64a8aaf --- /dev/null +++ b/src/homework4/circlelist/MainApp.java @@ -0,0 +1,38 @@ +/*Make a List of Circle objects. Use a random radius. Keep adding circles to the list until Math.random() + returns less than 0.01. Then, loop down the list and print out each area. +Note: To generate a random number use the following: +double rand = Math.random(); +To generate a random integer number in a range use: +(int)(Math.random*100);*/ + + +package homework4.circlelist; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; + +public class MainApp { + + public static void main(String[] args) { + + DecimalFormat df = new DecimalFormat("#.##"); + List circleList = new ArrayList<>(); + Double radius = 0.1; + while (radius != 0.01) { + + radius = Double.valueOf(df.format(Math.random())); + + System.out.println("radius = " + radius); + Circle circle = new Circle(); + circle.setRadius(radius); + circleList.add(circle); + } + System.out.println("circleList size = " + circleList.size()); + + for (Circle c : circleList) { + System.out.println("area = " + (3.14 * c.getRadius() * c.getRadius())); + } + + } +} From 0d697a04c18abd9fe9eed516b2c4db672e62a30f Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Mon, 13 Jan 2020 15:20:43 +0200 Subject: [PATCH 17/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- src/homework4/stringset/MainApp.java | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/homework4/stringset/MainApp.java diff --git a/src/homework4/stringset/MainApp.java b/src/homework4/stringset/MainApp.java new file mode 100644 index 0000000..4da0cfb --- /dev/null +++ b/src/homework4/stringset/MainApp.java @@ -0,0 +1,41 @@ +package homework4.stringset; + +import jdk.nashorn.internal.codegen.Compiler; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.stream.Stream; + +public class MainApp { + + public static void main(String[] args) { + Set setOfStocks = new HashSet<>(); + setOfStocks.add("INFY"); + setOfStocks.add("BABA"); + setOfStocks.add("GOOG"); + setOfStocks.add("MSFT"); + setOfStocks.add("AMZN"); + + + Iterator itr = setOfStocks.iterator(); // traversing over HashSet System.out.println("Traversing over Set using Iterator"); + while(itr.hasNext()){ + System.out.println(itr.next()); + } + + + System.out.println("Looping over HashSet using advanced for loop"); + for (String stock : setOfStocks) { + + System.out.println(stock); } + + System.out.println("stream"); + + Stream stringStream=setOfStocks.stream(); + + stringStream.forEach(elem-> System.out.println(elem+" ")); + + + } + +} From 7b3d5fe2590d3c134ffdbba03aaaff95bbedab14 Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Sat, 18 Jan 2020 12:32:07 +0200 Subject: [PATCH 18/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- src/homework4/mapofemplyees/MainApp.java | 85 ++++++++++++++++++++++++ src/homework4/stringset/MainApp.java | 50 +++++++++----- 2 files changed, 119 insertions(+), 16 deletions(-) create mode 100644 src/homework4/mapofemplyees/MainApp.java diff --git a/src/homework4/mapofemplyees/MainApp.java b/src/homework4/mapofemplyees/MainApp.java new file mode 100644 index 0000000..12ca47e --- /dev/null +++ b/src/homework4/mapofemplyees/MainApp.java @@ -0,0 +1,85 @@ +package homework4.mapofemplyees; + + + +//Suppose you have a Map of employees, where the key is their age and the value is their name sorted in alphabetical order. Write a Java program that: +// Declares and initializes the map +// Adds values to it +// Add values for a key that is not yet present in the map +// Iterate over the map’s keySet and prints the name of the employes for that key +// Iterate over the map’s entrySet and displays the first person alphabetically + + +import java.util.*; + +import java.util.Comparator; + +public class MainApp { + + public static void main(String[] args) { + Map employee = new HashMap(); + + + employee.put(30, ("Jhon")); + employee.put(20, ("Traian")); + employee.put(10, ("Pull")); + employee.put(5, null); + + + String studentsWith5 = employee.get(5); + if (studentsWith5 == null) { + studentsWith5 = new String(); + } + studentsWith5=("Abra"); + employee.put(5, studentsWith5); + + Set employeeKeySet = employee.keySet(); + System.out.println("Employee key set: " + employeeKeySet); + + + + + + Set> entries = employee.entrySet(); + System.out.println("Employee entry set: " + entries); + + + + Comparator> valueComparator = new Comparator>() { + + + + + + @Override + public int compare(Map.Entry e1, Map.Entry e2) { + String v1 = e1.getValue(); + String v2 = e2.getValue(); + return v1.compareTo(v2); + } + }; + + + System.out.println("#########################################"); + + List> listOfEntries = new ArrayList>(entries); + + // sorting HashMap by values using comparator + Collections.sort(listOfEntries, valueComparator); + + LinkedHashMap sortedByValue = new LinkedHashMap(listOfEntries.size()); + + // copying entries from List to Map + for(Map.Entry entry : listOfEntries){ + sortedByValue.put(entry.getKey(), entry.getValue()); + } + + System.out.println("HashMap after sorting entries by values "); + Set> entrySetSortedByValue = sortedByValue.entrySet(); + + for(Map.Entry mapping : entrySetSortedByValue){ + System.out.println(mapping.getKey() + " ==> " + mapping.getValue()); + } + + } +} diff --git a/src/homework4/stringset/MainApp.java b/src/homework4/stringset/MainApp.java index 4da0cfb..458fca9 100644 --- a/src/homework4/stringset/MainApp.java +++ b/src/homework4/stringset/MainApp.java @@ -1,39 +1,57 @@ package homework4.stringset; -import jdk.nashorn.internal.codegen.Compiler; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; + +//Suppose you have a set s containing some strings. +// Write a code fragment that uses an iterator to print out each element in set. +// Write a code fragment that uses a for to iterate over element +// Write a code fragment that uses the set stream() and the following methods: +// map to make a transformation of your choosing, filter based on a rule of your choosing, and collect, +// to collect all the strings separated by “,” with the prefix “This are the results: “ and sufix “ . Thank you!” + + +import java.util.*; +import java.util.stream.Collectors; import java.util.stream.Stream; public class MainApp { public static void main(String[] args) { - Set setOfStocks = new HashSet<>(); - setOfStocks.add("INFY"); - setOfStocks.add("BABA"); - setOfStocks.add("GOOG"); - setOfStocks.add("MSFT"); - setOfStocks.add("AMZN"); + Set s = new HashSet<>(); + s.add("MNFY"); + s.add("BABA"); + s.add("GOOG"); + s.add("MSFT"); + s.add("AMZN"); - Iterator itr = setOfStocks.iterator(); // traversing over HashSet System.out.println("Traversing over Set using Iterator"); - while(itr.hasNext()){ + Iterator itr = s.iterator(); + while(itr.hasNext()){ System.out.println(itr.next()); } System.out.println("Looping over HashSet using advanced for loop"); - for (String stock : setOfStocks) { + for (String stock : s) { System.out.println(stock); } - System.out.println("stream"); + System.out.println("_________________________"); + + Stream stringStream=s.stream(); + - Stream stringStream=setOfStocks.stream(); + stringStream.filter(e->{ +// System.out.println("filter : " + e); + return e.startsWith("M"); + }) + .map(elem -> { + System.out.println(" map: " + elem); + return elem.toLowerCase(); + }) + .collect(Collectors.joining(" , ","Prefix:", ":Suffix")); + System.out.println("Joined: " + stringStream); - stringStream.forEach(elem-> System.out.println(elem+" ")); } From 872bfba1fb12d3f88f95a454bfb52c6930ecf735 Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Sun, 19 Jan 2020 15:17:42 +0200 Subject: [PATCH 19/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- src/homework4/stringset/MainApp.java | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/homework4/stringset/MainApp.java b/src/homework4/stringset/MainApp.java index 458fca9..160baf9 100644 --- a/src/homework4/stringset/MainApp.java +++ b/src/homework4/stringset/MainApp.java @@ -38,19 +38,22 @@ public static void main(String[] args) { System.out.println("_________________________"); - Stream stringStream=s.stream(); - - - stringStream.filter(e->{ -// System.out.println("filter : " + e); - return e.startsWith("M"); - }) - .map(elem -> { - System.out.println(" map: " + elem); - return elem.toLowerCase(); - }) - .collect(Collectors.joining(" , ","Prefix:", ":Suffix")); - System.out.println("Joined: " + stringStream); + + + + String joined = s.stream() + .filter(elem -> { + System.out.println("filter : " + elem); + return elem.startsWith("M"); + }) + .map(elem -> { + System.out.println(" map: " + elem); + return elem.toLowerCase(); + }) + .collect(Collectors.joining(", ", "Prefix: ", " :Suffix")); + + System.out.println("Joined: " + joined); + From 340db7040bf3e0381df7b213428b2cebcb2cc4c4 Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Mon, 20 Jan 2020 13:24:20 +0200 Subject: [PATCH 20/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- .../lambdas/FunctionalInterface.java | 5 +++ src/homework4/lambdas/MainApp.java | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/homework4/lambdas/FunctionalInterface.java create mode 100644 src/homework4/lambdas/MainApp.java diff --git a/src/homework4/lambdas/FunctionalInterface.java b/src/homework4/lambdas/FunctionalInterface.java new file mode 100644 index 0000000..090968e --- /dev/null +++ b/src/homework4/lambdas/FunctionalInterface.java @@ -0,0 +1,5 @@ +package homework4.lambdas; +@java.lang.FunctionalInterface +public interface FunctionalInterface { + void operation(Number param1, Number param2); +} diff --git a/src/homework4/lambdas/MainApp.java b/src/homework4/lambdas/MainApp.java new file mode 100644 index 0000000..c777b7c --- /dev/null +++ b/src/homework4/lambdas/MainApp.java @@ -0,0 +1,37 @@ +package homework4.lambdas; + +//Write a functional interface with an abstract method called operation with 2 Number parameters +// (by Number I refer to the java class in java.lang.Number). Then in main, create a method named “operate” +// that has 2 Number parameters and the 3rd parameter is the functional interface you created. +// Then in main, add 3 lambda implementations of the functional interface with addition, multiplication, +// substraction and division, then call the operate method with input values and each operation in part. + +public class MainApp { + private void operate(Number number1, Number number2, FunctionalInterface functionalInterface) { + + } + + public static void main(String[] args) { +FunctionalInterface addition=(Number x1,Number x2)->{ + + Number c = x1.intValue() + x2.intValue(); + System.out.println("Addition: "+ c.intValue()); +}; + FunctionalInterface multiplication=(Number x1,Number x2)->{ + System.out.println("multiplication: "+(int)x1*(int)x2); + }; + FunctionalInterface substraction=(Number x1,Number x2)->{ + Number s=(int)x1-(int)x2; + + System.out.println("substraction: "+s); + }; + FunctionalInterface division=(Number x1,Number x2)->{ + System.out.println("division "+(int)x1/(int)x2); + }; + +addition.operation(3,11); +multiplication.operation(3,3); +substraction.operation(8,2); +division.operation(14,2); + } +} From 2ebd667eb5a499982a9e61eea5db6b47003d7b1d Mon Sep 17 00:00:00 2001 From: MariusHerlea Date: Wed, 22 Jan 2020 13:45:40 +0200 Subject: [PATCH 21/21] Merge remote-tracking branch 'origin/master' # Conflicts: # src/Homework1.java toString --- src/homework4/mapofemplyees/MainApp.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/homework4/mapofemplyees/MainApp.java b/src/homework4/mapofemplyees/MainApp.java index 12ca47e..b58938a 100644 --- a/src/homework4/mapofemplyees/MainApp.java +++ b/src/homework4/mapofemplyees/MainApp.java @@ -2,7 +2,8 @@ -//Suppose you have a Map of employees, where the key is their age and the value is their name sorted in alphabetical order. Write a Java program that: +//Suppose you have a Map of employees, where the key is their age and the value is their name sorted in alphabetical order. +// Write a Java program that: // Declares and initializes the map // Adds values to it // Add values for a key that is not yet present in the map @@ -33,6 +34,10 @@ public static void main(String[] args) { studentsWith5=("Abra"); employee.put(5, studentsWith5); + + + + Set employeeKeySet = employee.keySet(); System.out.println("Employee key set: " + employeeKeySet);