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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions src/main/java/myPkg/casting/Casting.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package myPkg.casting;

/**
*
* @author laura
*/
public class Casting {

public static void main(String[] args) {
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package casting;
import java.util.*;
/**
*
* @author addav
*/
public class Casting {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

ArrayList<Object> list = new ArrayList<>();
list.add(new Circle(1.0));
list.add(new Date());
list.add("String");
list.add(new Rectangle(2.0, 3.0));

for(int i = 0; i<list.size(); i++){
if(list.get(i) instanceof Circle){
System.out.println("The object is a circle and its radius is "+((Circle)list.get(i)).getRadius());
}
if(list.get(i) instanceof Date){
System.out.println("The object is a date and the date is "+((Date)list.get(i)).toString());
}
if (list.get(i) instanceof Rectangle){
System.out.println("The object is a rectangle and its height its height is "+((Rectangle)list.get(i)).getHeight());
}
}
}

}
44 changes: 44 additions & 0 deletions src/main/java/myPkg/inheritance/MyStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testmystack;

import java.util.*;

/**
*
* @author addav
*/
public class MyStack extends ArrayList{
private ArrayList<Object> list;

@Override
public boolean isEmpty(){
return super.size() == 0;
}

public int getSize(){
return super.size();
}

public Object peek(){
return super.get(getSize()-1);
}

public Object pop(){
Object a = super.get(getSize()-1);
super.remove(getSize()-1);
return a;
}

public void push(Object a){
super.add(a);
}

@Override
public String toString(){
return "Stack: "+super.toString();
}
}