javaproj5/.classpath
javaproj5/.project
javaproj5
org.eclipse.jdt.core.javabuilder
org.eclipse.jdt.core.javanature
javaproj5/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=15
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=15
javaproj5/bin/assignment4/Batman.class
javaproj5/bin/assignment4/Game.class
javaproj5/bin/assignment4/outputs1.docx
Loop runs until batman or superman is dead. If one of them health becomes 0, loop ends.
In the loop, each of the superhero attacks each other and opponents health decreases randomly.
javaproj5/bin/assignment4/SuperHero.class
javaproj5/bin/assignment4/Superman.class
javaproj5/bin/assingment5/Bomb.class
javaproj5/bin/assingment5/Game.class
javaproj5/bin/assingment5/Gun.class
javaproj5/bin/assingment5/output2.docx
Bomb and Gun are sub classes of Weapons. Fireweapon from each of these classes is called with by giving a firing power. It also has overloaded fireweapon() method which calls the super class’s method.
Fireweapon method is called in respective sub classes from test method
Shows call to normal fireweapon method and also call to overloaded method.
Activate method is overridden in both the sub classes as it is made abstract in weapons class.
By making the weapon class final, we cannot extend it. Hence sub classes cannot be implementing the methods and variables of super class. Inheritance is not possible.
By making the weapon class final, we cannot extend it. Hence sub classes cannot be implementing the methods and variables of super class. Inheritance is not possible.
javaproj5/bin/assingment5/Weapon.class
javaproj5/bin/assingment6/output3.docx
Person class objects are created in test class. In Java, the == operator compares that two references are identical or not. Whereas the equals() method compares two objects. Objects are equal when they have the same state (usually comparing variables).
javaproj5/bin/assingment6/Person.class
javaproj5/bin/assingment6/Test.class
javaproj5/bin/assingment7/output4.docx
Person class has two methods running and walking. When they are called to show the action a particular person is performing. When running is called, running is set to true else running is set to false.
To string method is overridden in person class to tell about the person name.
10 persons are created with first and last names, they are sorted based on their last names.
New attribute age is added to person class. Then compareTo method is changed to compare ages of person object. Now they are sorted based on their age.
javaproj5/bin/assingment7/Person.class
javaproj5/bin/assingment7/PersonInterface.class
javaproj5/bin/assingment7/Test.class
javaproj5/bin/assingment8/Circle.class
javaproj5/bin/assingment8/Rectangle.class
javaproj5/bin/assingment8/RegularHexagon.class
javaproj5/bin/assingment8/ShapeBase.class
javaproj5/bin/assingment8/ShapeInterface.class
javaproj5/bin/assingment8/Test.class
javaproj5/bin/assingment8/Triangle.class
javaproj5/src/assignment4/Batman.java
javaproj5/src/assignment4/Batman.java
package assignment4;
public class Batman extends SuperHero{
public Batman(int health)
{
super("Batman",health);
}
}
javaproj5/src/assignment4/Game.java
javaproj5/src/assignment4/Game.java
package assignment4;
import java.util.Random;
public class Game {
public static void main(String[] args) {
Random rand = new Random();
int health1 = rand.ints(1,(1000+1)).findFirst().getAsInt();
int health2 = rand.ints(1,(1000+1)).findFirst().getAsInt();
System.out.println("Creating our super heros....");
Superman superman = new Superman(health1);
Batman batman = new Batman(health2);
System.out.println("super heros created!");
System.out.println("running our game......");
while(!superman.isDead() && !batman.isDead())
{
superman.attack(batman);
batman.attack(superman);
if(superman.isDead())
{
System.out.println("Batman defeated superman");
}
if(batman.isDead())
{
System.out.println("superman defeated batman");
}
}
}
}
javaproj5/src/assignment4/outputs1.docx
Loop runs until batman or superman is dead. If one of them health becomes 0, loop ends.
In the loop, each of the superhero attacks each other and opponents health decreases randomly.
javaproj5/src/assignment4/SuperHero.java
javaproj5/src/assignment4/SuperHero.java
package assignment4;
import java.util.Random;
public class SuperHero {
String name;
int health;
boolean isDead;
public SuperHero(String name,int health)
{
this.name = name;
this.health = health;
}
public SuperHero() {
}
public void attack(SuperHero opponent)
{
Random rand = new Random();
int damage = rand.ints(1,(10+1)).findFirst().getAsInt();
opponent.determineHealth(damage);
System.out.println(String.format("%s has damage of %d and health of %d", opponent.name, damage,opponent.health));
}
private void determineHealth(int damage) {
if(this.health-damage<=0)
{
this.health = 0;
this.isDead = true;
}
else
{
this.health -= damage;
}
}
public boolean isDead()
{
return this.isDead;
}
}
javaproj5/src/assignment4/Superman.java
javaproj5/src/assignment4/Superman.java
package assignment4;
public class Superman extends SuperHero{
public Superman(int health)
{
super("Superman",health);
}
}
javaproj5/src/assingment5/Bomb.java
javaproj5/src/assingment5/Bomb.java
package assingment5;
public class Bomb extends Weapon {
public void fireWeapon(int power)
{
System.out.println("In Bomb.fireWeapon() with a power of "+ power);
}
public void fireWeapon() {
System.out.println("In overloaded Bomb.fireWeapon()");
super.fireWeapon(10);
}
@Override
public void activate(boolean enable) {
System.out.println("In the Bomb.activate() with an enable of "+ enable);
}
}
javaproj5/src/assingment5/Game.java
javaproj5/src/assingment5/Game.java
package assingment5;
public class Game {
public static void main(String[] args) {
Bomb weapon1= new Bomb();
Gun weapon2 = new Gun();
weapon1.fireWeapon(10);
weapon2.fireWeapon(5);
weapon1.fireWeapon();
weapon2.fireWeapon();
weapon1.activate(true);
weapon2.activate(true);
}
}
javaproj5/src/assingment5/Gun.java
javaproj5/src/assingment5/Gun.java
package assingment5;
public class Gun extends Weapon{
public void fireWeapon(int power)
{
System.out.println("In Gun.fireWeapon() with a power of "+ power);
}
public void fireWeapon() {
System.out.println("In overloaded Bomb.fireWeapon()");
super.fireWeapon(10);
}
@Override
public void activate(boolean enable) {
System.out.println("In the Gun.activate() with an enable of "+ enable);
}
}
javaproj5/src/assingment5/output2.docx
Bomb and Gun are sub classes of Weapons. Fireweapon from each of these classes is called with by giving a firing power. It also has overloaded fireweapon() method which calls the super class’s method.
Fireweapon method is called in respective sub classes from test method
Shows call to normal fireweapon method and also call to overloaded method.
Activate method is overridden in both the sub classes as it is made abstract in weapons class.
By making the weapon class final, we cannot extend it. Hence sub classes cannot be implementing the methods and variables of super class. Inheritance is not possible.
By making the weapon class final, we cannot extend it. Hence sub classes cannot be implementing the methods and variables of super class. Inheritance is not possible.
javaproj5/src/assingment5/Weapon.java
javaproj5/src/assingment5/Weapon.java
package assingment5;
public abstract class Weapon {
public void fireWeapon(int power)
{
System.out.println("In Weapon.fireWeapon() with a power of "+power);
}
public abstract void activate(boolean enable);
}
javaproj5/src/assingment6/output3.docx
Person class objects are created in test class. In Java, the == operator compares that two references are identical or not. Whereas the equals() method compares two objects. Objects are equal when they have the same state (usually comparing variables).
javaproj5/src/assingment6/Person.java
javaproj5/src/assingment6/Person.java
package assingment6;
public class Person {
private String firstName;
private String lastName;
public Person(String fname,String lname)
{
this.firstName = fname;
this.lastName = lname;
}
public Person(Person person)
{
this.firstName = person.firstName;
this.lastName = person.lastName;
}
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;
}
@Override
public boolean equals(Object other)
{
if(other==this)
{
System.out.println("I am here in other==this");
return true;
}
if(other==null)
{
System.out.println("I am here in other==null");
return false;
}
if(getClass()!=other.getClass())
{
System.out.println("I am here in getClass() != other.getClass()");
return false;
}
Person person = (Person)other;
return (this.firstName==person.firstName && this.lastName==person.lastName);
}
@Override
public String toString()
{
return "My class is "+getClass()+" "+this.firstName+" "+this.lastName;
}
}
javaproj5/src/assingment6/Test.java
javaproj5/src/assingment6/Test.java
package assingment6;
public class Test {
public static void main(String[] args) {
Person person1 = new Person("Briana", "Reha");
Person person2 = new Person("Justine", "Reha");
Person person3 = new Person(person1);
if(person1==person2)
{
System.out.println("These persons are identical using ==");
}
else
{
System.out.println("These persons are not identical usig ==");
}
if(person1.equals(person2))
{
System.out.println("These persons are identical using .equals()");
}
else
{
System.out.println("These persons are not identical usig .equals()");
}
if(person1.equals(person3))
{
System.out.println("These persons are identical using .equals()");
}
else
{
System.out.println("These persons are not identical usig .equals()");
}
System.out.println(person1.toString());
System.out.println(person2.toString());
System.out.println(person3.toString());
}
}
javaproj5/src/assingment7/output4.docx
Person class has two methods running and walking. When they are called to show the action a particular person is performing. When running is called, running is set to true else running is set to false.
To string method is overridden in person class to tell about the person name.
10 persons are created with first and last names, they are sorted based on their last names.
New attribute age is added to person class. Then compareTo method is changed to compare ages of person object. Now they are sorted based on their age.
javaproj5/src/assingment7/Person.java
javaproj5/src/assingment7/Person.java
package assingment7;
public class Person implements PersonInterface, Comparable
{
private String firstName = "Mark";
private String lastName="Reha";
private boolean running;
private Integer age;
public Person(String fname,String lname,int age)
{
this.firstName = fname;
this.lastName = lname;
this.age = age;
}
public Person(Person person)
{
this.firstName = person.firstName;
this.lastName = person.lastName;
}
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 int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public boolean equals(Object other)
{
if(other==this)
{
System.out.println("I am here in other==this");
return true;
}
if(other==null)
{
System.out.println("I am here in other==null");
return false;
}
if(getClass()!=other.getClass())
{
System.out.println("I am here in getClass() != other.getClass()");
return false;
}
Person person = (Person)other;
return (this.firstName==person.firstName && this.lastName==person.lastName);
}
@Override
public String toString()
{
return "My class is "+getClass()+" "+this.firstName+" "+this.lastName + " age is " + this.age;
}
@Override
public void walk() {
System.out.println("I am walking");
running = false;
}
@Override
public void run() {
System.out.println("I am running");
running = true;
}
@Override
public boolean isRunning() {
return running;
}
@Override
public int compareTo(Person p ) {
int val = this.age.compareTo(p.age);
if(val==0)
{
return this.age.compareTo(p.age);
}
else
{
return val;
}
}
}
javaproj5/src/assingment7/PersonInterface.java
javaproj5/src/assingment7/PersonInterface.java
package assingment7;
public interface PersonInterface {
public void walk();
public void run();
public boolean isRunning();
int compareTo(Person p);
}
javaproj5/src/assingment7/Test.java
javaproj5/src/assingment7/Test.java
package assingment7;
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
Person person1 = new Person("Briana", "Reha",10);
Person person2 = new Person("Justine", "Reha",20);
Person person3 = new Person(person1);
if(person1==person2)
{
System.out.println("These persons are identical using ==");
}
else
{
System.out.println("These persons are not identical usig ==");
}
if(person1.equals(person2))
{
System.out.println("These persons are identical using .equals()");
}
else
{
System.out.println("These persons are not identical usig .equals()");
}
if(person1.equals(person3))
{
System.out.println("These persons are identical using .equals()");
}
else
{
System.out.println("These persons are not identical usig .equals()");
}
System.out.println(person1.toString());
System.out.println(person2.toString());
System.out.println(person3.toString());
person1.walk();
person1.run();
System.out.println("Persn 1 is running: "+person1.isRunning());
person1.walk();
System.out.println("Persn 1 is running: "+person1.isRunning());
Person[] persons = new Person[10];
persons[0] = new Person("Justin","Bieber",22);
persons[1] = new Person("Justin","Reha",23);
persons[2] = new Person("Mary","Reha",54);
persons[3] = new Person("Mary","Obama",66);
persons[4] = new Person("Suzy","Obama",76);
persons[5] = new Person("Suzy","Reha",43);
persons[6] = new Person("Suzy","Hator",45);
persons[7] = new Person("Shawn","Hator",67);
persons[8] = new Person("Shawn","Mendes",78);
persons[9] = new Person("Susy","Mendes",87);
Arrays.sort(persons);
for(int i=0; i<10; i++)
{
System.out.println(persons[i]);
}
}
}
javaproj5/src/assingment8/Circle.java
javaproj5/src/assingment8/Circle.java
package assingment8;
public class Circle {
private int radius;
private String name;
public Circle(String name, int radius) {
this.radius = radius;
this.name = name;
}
public Double calculateArea()
{
return (3.14*2*this.radius*this.radius);
}
}
javaproj5/src/assingment8/newuml.mdj
{
"_type": "Project",
"_id": "AAAAAAFF+h6SjaM2Hec=",
"name": "Untitled",
"ownedElements": [
{
"_type": "UMLModel",
"_id": "AAAAAAFF+qBWK6M3Z8Y=",
"_parent": {
"$ref": "AAAAAAFF+h6SjaM2Hec="
},
"name": "Model",
"ownedElements": [
{
"_type": "UMLClassDiagram",
"_id": "AAAAAAFF+qBtyKM79qY=",
"_parent": {
"$ref": "AAAAAAFF+qBWK6M3Z8Y="
},
"name": "Main",
"defaultDiagram": true,
"ownedViews": [
{
"_type": "UMLClassView",
"_id": "AAAAAAF5avsXTjftDmg=",
"_parent": {
"$ref": "AAAAAAFF+qBtyKM79qY="
},
"model": {
"$ref": "AAAAAAF5avsXTDfr63g="
},
"subViews": [
{
"_type": "UMLNameCompartmentView",
"_id": "AAAAAAF5avsXTjfu2dA=",
"_parent": {
"$ref": "AAAAAAF5avsXTjftDmg="
},
"model": {
"$ref": "AAAAAAF5avsXTDfr63g="
},
"subViews": [
{
"_type": "LabelView",
"_id": "AAAAAAF5avsXTzfvTzk=",
"_parent": {
"$ref": "AAAAAAF5avsXTjfu2dA="
},
"visible": false,
"font": "Arial;13;0",
"height": 13
},
{
"_type": "LabelView",
"_id": "AAAAAAF5avsXTzfw1bs=",
"_parent": {
"$ref": "AAAAAAF5avsXTjfu2dA="
},
"font": "Arial;13;1",
"left":...