diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index d536cb0..71cc981 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -175,27 +175,29 @@ "switcher:Open quick switcher": false } }, - "active": "671043c113c40804", + "active": "13f4c5e19c9ab3c8", "lastOpenFiles": [ + "Semester 2/Programming 2/Week 1/java-apps/HelloWorld/HelloWorldApp.class", + "Semester 2/Programming 2/Week 1/java-apps/HelloWorld/start.sh", + "Semester 2/Programming 2/Week 1/java-apps/HelloWorld/HelloWorldApp.java", + "Semester 2/Programming 2/Week 1/java-apps/HelloWorld", + "Semester 2/Programming 2/Week 1/java-apps", + "Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.java#", + "Semester 2/Programming 2/Week 1/zoo-io-v3/__SHELL31.class", + "Semester 2/Programming 2/Week 1/zoo-io-v3/__SHELL31$1.class", + "Semester 2/Programming 2/Week 1/zoo-io-v3/__SHELL31.java", + "Semester 2/Programming 2/Week 1/zoo-io-v3/__SHELL30.class", + "Semester 2/Programming 2/Week 1/zoo-io-v3/__SHELL30$1.class", + "Semester 2/Computer Systems Internals & Linux/Week 1/workshop/testdir/test.md", + "Semester 2/Computer Systems Internals & Linux/Week 1/Week 1 Computer Systems Internals.md", "Semester 1/Database Systems/Week 11/Week 11 Database Systems.md", "Semester 1/Database Systems/Week 10/Week 10 Database Systems.md", "Semester 2/Database Systems/Week 1/Week 1 Database Systems.md", "Semester 1/Database Systems/Assignment/Querying Database.md", - "Semester 2/Database Systems/Week 1", - "Semester 2/Computer Systems Internals & Linux/Week 1/Week 1 Computer Systems Internals.md", - "Semester 2/Database Systems", "README.md", "Semester 2/Programming 2/Week 1/Week 1 Programming 2.md", - "Semester 2/Computer Systems Internals & Linux/Week 1", - "Semester 2/Programming 2/Week 1", - "Semester 2/Computer Systems Internals & Linux", - "Semester 2/Programming 2", - "Semester 2", - "Semester 1", "2023-10-31.md", "2024-01-15.md", - "Semester 1/Web Development and HCI/Assignment.odt", - "Web Development and HCI/lu11370hmnm.tmp", "Semester 1/Web Development and HCI/Assignment 1/src/images/proxmox-03.jpg", "Semester 1/Web Development and HCI/Assignment 1/src/images/proxmox-04.jpg", "Web Development and HCI/Assignment 1/src/images/Screenshot from 2023-12-07 18-29-51.png", @@ -221,7 +223,6 @@ "Semester 1/Computer Systems Internals & Linux/Coursework 1/Task 5.md", "Semester 1/Computer Systems Internals & Linux/Coursework 1/Task 3.md", "Semester 1/Computer Systems Internals & Linux/Coursework 1/Task 1.md", - "Semester 1/Computer Systems Internals & Linux/Coursework 1/Task 2.md", "Database Systems/Untitled.canvas", "Untitled 1.canvas", "Untitled.canvas" diff --git a/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/delete.sh b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/delete.sh new file mode 100755 index 0000000..028a30c --- /dev/null +++ b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/delete.sh @@ -0,0 +1,10 @@ +#!/bin/bash +if [ $# -eq 1 ] && [ -f $1 ]; then + mv $1 ./wastebasket/$1 + echo "file $1 moved to ./wastebasket/$1" +elif [ $# -eq 1] && [ -d $1 ]; then + mv -R $1 ./wastebasket/$1 + echo "directory $1 moved to ./wastebasket/$1" +else + echo "More than one file supplied" +fi diff --git a/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script1.sh b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script1.sh new file mode 100755 index 0000000..8ddeff1 --- /dev/null +++ b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script1.sh @@ -0,0 +1,14 @@ +#!/bin/bash +echo -n Enter num: +read num +if [ "$num" = "" ]; then + echo No input +elif echo $num | grep -Eq '[^0-9]'; then + echo Not an integer +elif [ $num -gt 5 ]; then + echo Greater than 5 +elif [ $num -eq 5 ]; then + echo Equal to 5 +else + echo Less than 5 +fi diff --git a/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script2.sh b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script2.sh new file mode 100755 index 0000000..5b52938 --- /dev/null +++ b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script2.sh @@ -0,0 +1,9 @@ +#!/bin/bash +for file in ~/*; do #For every item in the user's home directory. + if [ -d "$file" ]; then + echo $file is a directory + elif [ -f "$file" ]; then + lines=$(cat "$file" | wc -l) + echo $file is a file with $lines lines + fi +done diff --git a/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script3.sh b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script3.sh new file mode 100755 index 0000000..596b201 --- /dev/null +++ b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/script3.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [ $# -eq 2 ]; then + echo "2 arguments (\"$1\" and \"$2\")" +else + echo Please give me 2 arguments +fi diff --git a/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/testdir/test.md b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/testdir/test.md new file mode 100644 index 0000000..e69de29 diff --git a/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/testdir/test.txt b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/testdir/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/wastebasket/test.txt b/Semester 2/Computer Systems Internals & Linux/Week 1/workshop/wastebasket/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/Semester 2/Database Systems/Week 1/Week 1 Database Systems.md b/Semester 2/Database Systems/Week 1/Week 1 Database Systems.md index f82b146..447fcc2 100644 --- a/Semester 2/Database Systems/Week 1/Week 1 Database Systems.md +++ b/Semester 2/Database Systems/Week 1/Week 1 Database Systems.md @@ -1,7 +1,10 @@ -### [Relational Algebra - Recap](obsidian://open?vault=Computer%20Science%20Year%201&file=Semester%201%2FDatabase%20Systems%2FWeek%2010%2FWeek%2010) +### [Relational Algebra - Recap](obsidian://open?vault=Computer%20Science%20Year%201&file=Semester%201%2FDatabase%20Systems%2FWeek%2010%2FWeek%2010%20Database%20Systems) - High level & procedural - Defines how to build relations +- SELECT represented by pi ( projection ) +- FROM represented by sigma ( selection ) +- WHERE represented by x ( cartesian product ) #### Data Manipulation Language @@ -14,3 +17,21 @@ - Operations work on one or more relations to define another relation without changing the original - Both operands and results are relations, output from one operation can become the input for another operation. - This allows nested expressions. + +#### Theta Join + +R theta(f) S defines a relation that contains tuples satisfying F from the Cartesian product of two relations R and S. +Takes the Cartesian product of two relations r and s than selects the rows which satisfy the condition F. +R theta(f) S is the same as sigma(f) (R x S ). +F may contain comparison operators to form a condition. + +#### Query Processing +The activities involved in parsing, validating, optimising and executing a query. +Purpose is to transform a query written in a high level language into correct and efficient strategy in low level language. Also to execute strategy to retrieve data. + +#### Common Optimisation Rules +- Begin with initial query tree for SQL +- Move SELECT operations down the tree +- Apply more restrictive SELECT operations first ( eg. equalities before range queries ) +- Replace Cartesian products followed by selection with theta joins ( eg. *sigma(f) ( RxS )* -> *R theta(f) S* ) +- Move PROJECT operations down the query tree ( add project operations as inputs to theta joins ) \ No newline at end of file diff --git a/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/HelloWorldApp.class b/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/HelloWorldApp.class new file mode 100644 index 0000000..d933ad6 Binary files /dev/null and b/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/HelloWorldApp.class differ diff --git a/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/HelloWorldApp.java b/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/HelloWorldApp.java new file mode 100644 index 0000000..6241424 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/HelloWorldApp.java @@ -0,0 +1,13 @@ +/** + * The stand-alone HelloWorld application. + * + * @author (D.Evans + * @version 10/02/2004 + */ +public class HelloWorldApp +{ + public static void main(String[] args) + { + System.out.println("Hello World!"); + } +} diff --git a/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/start.sh b/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/start.sh new file mode 100755 index 0000000..ff35381 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/java-apps/HelloWorld/start.sh @@ -0,0 +1,2 @@ +javac ./HelloWorldApp.java +java HelloWorldApp diff --git a/Semester 2/Programming 2/Week 1/workshop/package.bluej b/Semester 2/Programming 2/Week 1/workshop/package.bluej new file mode 100644 index 0000000..2ad5966 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/workshop/package.bluej @@ -0,0 +1,40 @@ +#BlueJ package file +dependency1.from=Zoo +dependency1.to=Animal +dependency1.type=UsesDependency +objectbench.height=76 +objectbench.width=852 +package.editor.height=400 +package.editor.width=726 +package.editor.x=754 +package.editor.y=257 +package.numDependencies=1 +package.numTargets=2 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +target1.editor.height=700 +target1.editor.width=900 +target1.editor.x=70 +target1.editor.y=51 +target1.height=50 +target1.name=Animal +target1.showInterface=false +target1.type=ClassTarget +target1.typeParameters= +target1.width=80 +target1.x=70 +target1.y=10 +target2.editor.height=700 +target2.editor.width=900 +target2.editor.x=350 +target2.editor.y=130 +target2.height=50 +target2.name=Zoo +target2.naviview.expanded=true +target2.showInterface=false +target2.type=ClassTarget +target2.typeParameters= +target2.width=80 +target2.x=150 +target2.y=60 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.class b/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.class new file mode 100644 index 0000000..fab6eb4 Binary files /dev/null and b/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.class differ diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.ctxt b/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.ctxt new file mode 100644 index 0000000..82b69b4 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.ctxt @@ -0,0 +1,14 @@ +#BlueJ class context +comment0.params=species\ name +comment0.target=Animal(java.lang.String,\ java.lang.String) +comment0.text=\n\ Create\ an\ animal\ of\ the\ specified\ species\ and\ with\ the\ specified\ name\n\ \n\ @param\ \ species\ a\ String\ specifying\ the\n\ type\ of\ animal\n\ @param\ \ name\ a\ String\ specifying\ the\ \n\ name\ of\ animal\n +comment1.params= +comment1.target=java.lang.String\ getSpecies() +comment1.text=\n\ Returns\ the\ species\ of\ the\ Animal\ object\n\ \n\ @return\ \ \ the\ species\ of\ animal,\ as\ a\ String\n +comment2.params= +comment2.target=java.lang.String\ getName() +comment2.text=\n\ Returns\ the\ name\ of\ the\ Animal\ object\n\ \n\ @return\ \ \ the\ name\ of\ animal,\ as\ a\ String\n +comment3.params= +comment3.target=java.lang.String\ toString() +comment3.text=\n\ Returns\ a\ string\ representing\ the\ Animal\ object.\ \ For\ a\ \n\ lion\ with\ name\ Leo\ it\ will\ return\ the\ String\ "Leo,\ a\ lion"\n\ \n\ @return\ \ \ a\ String\ representation\ of\ the\ animal\n +numComments=4 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.java b/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.java new file mode 100644 index 0000000..6f76a2d --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v1/Animal.java @@ -0,0 +1,59 @@ +/** + * class Animal simulates an animal and stores + * the species and name. + * + * @author D Newton + * @version Version 1, 1 November 2010 + */ +public class Animal +{ + // species of the animal e.g. lion, tiger + private String species; + // name of the animal e.g. Leo, Tommy + private String name; + + /** + * Create an animal of the specified species and with the specified name + * + * @param species a String specifying the + * type of animal + * @param name a String specifying the + * name of animal + */ + public Animal(String species, String name) + { + this.species = species; + this.name = name; + } + + /** + * Returns the species of the Animal object + * + * @return the species of animal, as a String + */ + public String getSpecies() + { + return species; + } + + /** + * Returns the name of the Animal object + * + * @return the name of animal, as a String + */ + public String getName() + { + return name; + } + + /** + * Returns a string representing the Animal object. For a + * lion with name Leo it will return the String "Leo, a lion" + * + * @return a String representation of the animal + */ + public String toString() + { + return name + ", a " + species; + } +} \ No newline at end of file diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/README.TXT b/Semester 2/Programming 2/Week 1/zoo-io-v1/README.TXT new file mode 100644 index 0000000..2bea2dd --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v1/README.TXT @@ -0,0 +1,12 @@ +------------------------------------------------------------------------ +This is the project README file. Here, you should describe your project. +Tell the reader (someone who does not know anything about this project) +all he/she needs to know. The comments should usually include at least: +------------------------------------------------------------------------ + +PROJECT TITLE: +PURPOSE OF PROJECT: +VERSION or DATE: +HOW TO START THIS PROJECT: +AUTHORS: +USER INSTRUCTIONS: diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.class b/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.class new file mode 100644 index 0000000..efe85b4 Binary files /dev/null and b/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.class differ diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.ctxt b/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.ctxt new file mode 100644 index 0000000..8c75b75 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.ctxt @@ -0,0 +1,35 @@ +#BlueJ class context +comment0.params= +comment0.target=Zoo() +comment0.text=\n\ Create\ an\ "empty"\ zoo\n +comment1.params=fileName +comment1.target=Zoo(java.lang.String) +comment1.text=\n\ Create\ a\ zoo\ and\ populate\ it\ using\ data\ from\ a\ text\ file\n +comment10.params=fileName +comment10.target=void\ readAnimalData(java.lang.String) +comment10.text=\n\ Reads\ animal\ data\ from\ a\ file\ and\ adds\ corresponding\ animals\ to\ the\ zoo\n\n\ @param\ \ \ fileName\ a\ String,\ the\ name\ of\ the\ \n\ \ \ \ \ \ \ \ \ \ text\ file\ in\ which\ the\ data\ is\ stored.\n\ \n\ @throws\ \ FileNotFoundException\n +comment2.params=animal +comment2.target=void\ storeAnimal(Animal) +comment2.text=\n\ Adds\ an\ animal\ to\ the\ zoo\n\n\ @param\ \ \ animal\ an\ Animal\ object,\ the\ animal\ to\ be\ added\n +comment3.params=listPosition +comment3.target=void\ showAnimal(int) +comment3.text=\n\ Shows\ an\ animal\ by\ printing\ it's\ details.\ \ This\ includes\n\ it's\ position\ in\ the\ collection.\n\n\ @param\ \ listPosition\ the\ position\ of\ the\ animal\n +comment4.params= +comment4.target=int\ numberOfAnimals() +comment4.text=\n\ Returns\ how\ many\ animals\ are\ stored\ in\ the\ collection\n\n\ @return\ \ \ the\ number\ of\ animals\ in\ the\ collection\n +comment5.params= +comment5.target=void\ showAllAnimals() +comment5.text=\n\ Displays\ all\ the\ animals\ in\ the\ collection\n\n +comment6.params=listPosition +comment6.target=void\ removeAnimal(int) +comment6.text=\n\ Remove\ an\ animal\ from\ the\ collection\n\n\ @param\ \ listPosition\ the\ position\ of\ the\ animal\n +comment7.params= +comment7.target=void\ populate() +comment7.text=\n\ Adds\ a\ pre-defined\ set\ of\ animals\ to\ the\ current\ collection\n\n +comment8.params= +comment8.target=void\ countAnimals() +comment8.text=\n\ Counts\ the\ number\ of\ lions,\ tigers\ and\ elephants\n\n +comment9.params=fileName +comment9.target=void\ writeAnimalData(java.lang.String) +comment9.text=\n\ Writes\ animal\ data\ to\ a\ file\n\n\ @param\ \ \ fileName\ a\ String,\ the\ name\ of\ the\ \n\ \ \ \ \ \ \ \ \ \ text\ file\ in\ which\ the\ data\ will\ be\ stored.\n\ \n\ @throws\ \ FileNotFoundException\n +numComments=11 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.java b/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.java new file mode 100644 index 0000000..bff3c90 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v1/Zoo.java @@ -0,0 +1,192 @@ +import java.util.*; +import java.io.*; +/** + * class Zoo simulates storing animals in a collection. + * + * @author D Newton + * */ +public class Zoo +{ + private ArrayList animalCollection; + private int lionCount; + private int tigerCount; + private int elephantCount; + private int otherCount; + + /** + * Create an "empty" zoo + */ + public Zoo() + { + animalCollection = new ArrayList(); + lionCount = 0; + tigerCount = 0; + elephantCount = 0; + otherCount = 0; + } + + /** + * Create a zoo and populate it using data from a text file + */ + public Zoo(String fileName) throws FileNotFoundException + { + this(); + readAnimalData(fileName); + } + + /** + * Adds an animal to the zoo + * + * @param animal an Animal object, the animal to be added + */ + public void storeAnimal(Animal animal) + { + animalCollection.add(animal); + } + + /** + * Shows an animal by printing it's details. This includes + * it's position in the collection. + * + * @param listPosition the position of the animal + */ + public void showAnimal(int listPosition) + { + Animal animal; + if( listPosition < animalCollection.size() ) + { + animal = animalCollection.get(listPosition); + System.out.println("Position " + listPosition + ": " + animal); + } + } + + /** + * Returns how many animals are stored in the collection + * + * @return the number of animals in the collection + */ + public int numberOfAnimals() + { + return animalCollection.size(); + } + + /** + * Displays all the animals in the collection + * + */ + public void showAllAnimals() + { + System.out.println("Zoo"); + System.out.println("==="); + + int listPosition = 0; + while( listPositionlistPosition the position of the animal + */ + public void removeAnimal(int listPosition) + { + if( listPosition>=0 && listPosition it = animalCollection.iterator(); + while( it.hasNext() ) + { + Animal currentAnimal = it.next(); + String species = currentAnimal.getSpecies(); + if( species.equalsIgnoreCase("lion") ) + lionCount++; + else if( species.equalsIgnoreCase("tiger") ) + tigerCount++; + else if( species.equalsIgnoreCase("elephant") ) + elephantCount++; + else + otherCount++; + } + } + + /** + * Writes animal data to a file + * + * @param fileName a String, the name of the + * text file in which the data will be stored. + * + * @throws FileNotFoundException + */ + public void writeAnimalData(String fileName) throws FileNotFoundException + { + PrintWriter pWriter = new PrintWriter(fileName); + + for(Animal a: animalCollection) + { + String lineOfOutput = a.getName() + " " + a.getSpecies(); + pWriter.println(lineOfOutput); + } + pWriter.close(); + } + + /** + * Reads animal data from a file and adds corresponding animals to the zoo + * + * @param fileName a String, the name of the + * text file in which the data is stored. + * + * @throws FileNotFoundException + */ + public void readAnimalData(String fileName) throws FileNotFoundException + { + File dataFile = new File(fileName); + Scanner scanner = new Scanner(dataFile); + + while( scanner.hasNext() ) + { + String name = scanner.next(); + String species = scanner.next(); + storeAnimal( new Animal(species, name) ); + } + + scanner.close(); + } +} \ No newline at end of file diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/animal_data.txt b/Semester 2/Programming 2/Week 1/zoo-io-v1/animal_data.txt new file mode 100644 index 0000000..3739046 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v1/animal_data.txt @@ -0,0 +1,10 @@ +Leo lion +Tommy tiger +Ollie elephant +Roland rat +Rudolph reindeer +Lenny Lion +Nellie Elephant +Tessa tiger +Hetty eLephant +Leslie LION diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/new_animals.txt b/Semester 2/Programming 2/Week 1/zoo-io-v1/new_animals.txt new file mode 100644 index 0000000..95f7a14 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v1/new_animals.txt @@ -0,0 +1,3 @@ +Bobby bear +Andy aardvark +Polly parrot diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v1/package.bluej b/Semester 2/Programming 2/Week 1/zoo-io-v1/package.bluej new file mode 100644 index 0000000..e6cc546 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v1/package.bluej @@ -0,0 +1,3 @@ +#BlueJ package file +#Thu Jan 18 14:27:41 GMT 2024 +project.charset=UTF-8 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.class b/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.class new file mode 100644 index 0000000..fab6eb4 Binary files /dev/null and b/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.class differ diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.ctxt b/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.ctxt new file mode 100644 index 0000000..82b69b4 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.ctxt @@ -0,0 +1,14 @@ +#BlueJ class context +comment0.params=species\ name +comment0.target=Animal(java.lang.String,\ java.lang.String) +comment0.text=\n\ Create\ an\ animal\ of\ the\ specified\ species\ and\ with\ the\ specified\ name\n\ \n\ @param\ \ species\ a\ String\ specifying\ the\n\ type\ of\ animal\n\ @param\ \ name\ a\ String\ specifying\ the\ \n\ name\ of\ animal\n +comment1.params= +comment1.target=java.lang.String\ getSpecies() +comment1.text=\n\ Returns\ the\ species\ of\ the\ Animal\ object\n\ \n\ @return\ \ \ the\ species\ of\ animal,\ as\ a\ String\n +comment2.params= +comment2.target=java.lang.String\ getName() +comment2.text=\n\ Returns\ the\ name\ of\ the\ Animal\ object\n\ \n\ @return\ \ \ the\ name\ of\ animal,\ as\ a\ String\n +comment3.params= +comment3.target=java.lang.String\ toString() +comment3.text=\n\ Returns\ a\ string\ representing\ the\ Animal\ object.\ \ For\ a\ \n\ lion\ with\ name\ Leo\ it\ will\ return\ the\ String\ "Leo,\ a\ lion"\n\ \n\ @return\ \ \ a\ String\ representation\ of\ the\ animal\n +numComments=4 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.java b/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.java new file mode 100644 index 0000000..6f76a2d --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v2/Animal.java @@ -0,0 +1,59 @@ +/** + * class Animal simulates an animal and stores + * the species and name. + * + * @author D Newton + * @version Version 1, 1 November 2010 + */ +public class Animal +{ + // species of the animal e.g. lion, tiger + private String species; + // name of the animal e.g. Leo, Tommy + private String name; + + /** + * Create an animal of the specified species and with the specified name + * + * @param species a String specifying the + * type of animal + * @param name a String specifying the + * name of animal + */ + public Animal(String species, String name) + { + this.species = species; + this.name = name; + } + + /** + * Returns the species of the Animal object + * + * @return the species of animal, as a String + */ + public String getSpecies() + { + return species; + } + + /** + * Returns the name of the Animal object + * + * @return the name of animal, as a String + */ + public String getName() + { + return name; + } + + /** + * Returns a string representing the Animal object. For a + * lion with name Leo it will return the String "Leo, a lion" + * + * @return a String representation of the animal + */ + public String toString() + { + return name + ", a " + species; + } +} \ No newline at end of file diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/README.TXT b/Semester 2/Programming 2/Week 1/zoo-io-v2/README.TXT new file mode 100644 index 0000000..2bea2dd --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v2/README.TXT @@ -0,0 +1,12 @@ +------------------------------------------------------------------------ +This is the project README file. Here, you should describe your project. +Tell the reader (someone who does not know anything about this project) +all he/she needs to know. The comments should usually include at least: +------------------------------------------------------------------------ + +PROJECT TITLE: +PURPOSE OF PROJECT: +VERSION or DATE: +HOW TO START THIS PROJECT: +AUTHORS: +USER INSTRUCTIONS: diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.class b/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.class new file mode 100644 index 0000000..ec021b2 Binary files /dev/null and b/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.class differ diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.ctxt b/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.ctxt new file mode 100644 index 0000000..8c75b75 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.ctxt @@ -0,0 +1,35 @@ +#BlueJ class context +comment0.params= +comment0.target=Zoo() +comment0.text=\n\ Create\ an\ "empty"\ zoo\n +comment1.params=fileName +comment1.target=Zoo(java.lang.String) +comment1.text=\n\ Create\ a\ zoo\ and\ populate\ it\ using\ data\ from\ a\ text\ file\n +comment10.params=fileName +comment10.target=void\ readAnimalData(java.lang.String) +comment10.text=\n\ Reads\ animal\ data\ from\ a\ file\ and\ adds\ corresponding\ animals\ to\ the\ zoo\n\n\ @param\ \ \ fileName\ a\ String,\ the\ name\ of\ the\ \n\ \ \ \ \ \ \ \ \ \ text\ file\ in\ which\ the\ data\ is\ stored.\n\ \n\ @throws\ \ FileNotFoundException\n +comment2.params=animal +comment2.target=void\ storeAnimal(Animal) +comment2.text=\n\ Adds\ an\ animal\ to\ the\ zoo\n\n\ @param\ \ \ animal\ an\ Animal\ object,\ the\ animal\ to\ be\ added\n +comment3.params=listPosition +comment3.target=void\ showAnimal(int) +comment3.text=\n\ Shows\ an\ animal\ by\ printing\ it's\ details.\ \ This\ includes\n\ it's\ position\ in\ the\ collection.\n\n\ @param\ \ listPosition\ the\ position\ of\ the\ animal\n +comment4.params= +comment4.target=int\ numberOfAnimals() +comment4.text=\n\ Returns\ how\ many\ animals\ are\ stored\ in\ the\ collection\n\n\ @return\ \ \ the\ number\ of\ animals\ in\ the\ collection\n +comment5.params= +comment5.target=void\ showAllAnimals() +comment5.text=\n\ Displays\ all\ the\ animals\ in\ the\ collection\n\n +comment6.params=listPosition +comment6.target=void\ removeAnimal(int) +comment6.text=\n\ Remove\ an\ animal\ from\ the\ collection\n\n\ @param\ \ listPosition\ the\ position\ of\ the\ animal\n +comment7.params= +comment7.target=void\ populate() +comment7.text=\n\ Adds\ a\ pre-defined\ set\ of\ animals\ to\ the\ current\ collection\n\n +comment8.params= +comment8.target=void\ countAnimals() +comment8.text=\n\ Counts\ the\ number\ of\ lions,\ tigers\ and\ elephants\n\n +comment9.params=fileName +comment9.target=void\ writeAnimalData(java.lang.String) +comment9.text=\n\ Writes\ animal\ data\ to\ a\ file\n\n\ @param\ \ \ fileName\ a\ String,\ the\ name\ of\ the\ \n\ \ \ \ \ \ \ \ \ \ text\ file\ in\ which\ the\ data\ will\ be\ stored.\n\ \n\ @throws\ \ FileNotFoundException\n +numComments=11 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.java b/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.java new file mode 100644 index 0000000..e5f6a99 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v2/Zoo.java @@ -0,0 +1,194 @@ +import java.util.*; +import java.io.*; +/** + * class Zoo simulates storing animals in a collection. + * + * @author D Newton + * */ +public class Zoo +{ + private ArrayList animalCollection; + private int lionCount; + private int tigerCount; + private int elephantCount; + private int otherCount; + + /** + * Create an "empty" zoo + */ + public Zoo() + { + animalCollection = new ArrayList(); + lionCount = 0; + tigerCount = 0; + elephantCount = 0; + otherCount = 0; + } + + /** + * Create a zoo and populate it using data from a text file + */ + public Zoo(String fileName) throws FileNotFoundException + { + this(); + readAnimalData(fileName); + } + + /** + * Adds an animal to the zoo + * + * @param animal an Animal object, the animal to be added + */ + public void storeAnimal(Animal animal) + { + animalCollection.add(animal); + } + + /** + * Shows an animal by printing it's details. This includes + * it's position in the collection. + * + * @param listPosition the position of the animal + */ + public void showAnimal(int listPosition) + { + Animal animal; + if( listPosition < animalCollection.size() ) + { + animal = animalCollection.get(listPosition); + System.out.println("Position " + listPosition + ": " + animal); + } + } + + /** + * Returns how many animals are stored in the collection + * + * @return the number of animals in the collection + */ + public int numberOfAnimals() + { + return animalCollection.size(); + } + + /** + * Displays all the animals in the collection + * + */ + public void showAllAnimals() + { + System.out.println("Zoo"); + System.out.println("==="); + + int listPosition = 0; + while( listPositionlistPosition the position of the animal + */ + public void removeAnimal(int listPosition) + { + if( listPosition>=0 && listPosition it = animalCollection.iterator(); + while( it.hasNext() ) + { + Animal currentAnimal = it.next(); + String species = currentAnimal.getSpecies(); + if( species.equalsIgnoreCase("lion") ) + lionCount++; + else if( species.equalsIgnoreCase("tiger") ) + tigerCount++; + else if( species.equalsIgnoreCase("elephant") ) + elephantCount++; + else + otherCount++; + } + } + + /** + * Writes animal data to a file + * + * @param fileName a String, the name of the + * text file in which the data will be stored. + * + * @throws FileNotFoundException + */ + public void writeAnimalData(String fileName) throws FileNotFoundException + { + PrintWriter pWriter = new PrintWriter(fileName); + + for(Animal a: animalCollection) + { + String lineOfOutput = a.getName() + "," + a.getSpecies(); + pWriter.println(lineOfOutput); + } + pWriter.close(); + } + + /** + * Reads animal data from a file and adds corresponding animals to the zoo + * + * @param fileName a String, the name of the + * text file in which the data is stored. + * + * @throws FileNotFoundException + */ + public void readAnimalData(String fileName) throws FileNotFoundException + { + File dataFile = new File(fileName); + Scanner scanner = new Scanner(dataFile); + scanner.useDelimiter("[,\n]"); + + while( scanner.hasNext() ) + { + String name = scanner.next(); + name.trim(); + String species = scanner.next(); + species.trim(); + storeAnimal( new Animal(species, name) ); + } + scanner.close(); + } +} \ No newline at end of file diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/animal_data.txt b/Semester 2/Programming 2/Week 1/zoo-io-v2/animal_data.txt new file mode 100644 index 0000000..077e4e6 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v2/animal_data.txt @@ -0,0 +1,10 @@ +Leo, Lion +Tommy, Tiger +Ollie, Elephant +Roland, Rat +Rudolph, Reindeer +Lenny, Lion +Nellie, Elephant +Tessa, Tiger +Hetty, Elephant +Leslie, Lion diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/new_animals.txt b/Semester 2/Programming 2/Week 1/zoo-io-v2/new_animals.txt new file mode 100644 index 0000000..0207d8e --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v2/new_animals.txt @@ -0,0 +1,3 @@ +Bobby, Bear +Andy, Aardvark +Polly, African Grey Parrot diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v2/package.bluej b/Semester 2/Programming 2/Week 1/zoo-io-v2/package.bluej new file mode 100644 index 0000000..db83f6c --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v2/package.bluej @@ -0,0 +1,36 @@ +#BlueJ package file +dependency1.from=Zoo +dependency1.to=Animal +dependency1.type=UsesDependency +objectbench.height=76 +objectbench.width=686 +package.editor.height=400 +package.editor.width=560 +package.editor.x=774 +package.editor.y=277 +package.numDependencies=1 +package.numTargets=2 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +target1.height=50 +target1.name=Animal +target1.showInterface=false +target1.type=ClassTarget +target1.typeParameters= +target1.width=80 +target1.x=90 +target1.y=10 +target2.editor.height=700 +target2.editor.width=900 +target2.editor.x=814 +target2.editor.y=297 +target2.height=50 +target2.name=Zoo +target2.naviview.expanded=true +target2.showInterface=false +target2.type=ClassTarget +target2.typeParameters= +target2.width=80 +target2.x=180 +target2.y=10 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.class b/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.class new file mode 100644 index 0000000..fab6eb4 Binary files /dev/null and b/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.class differ diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.ctxt b/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.ctxt new file mode 100644 index 0000000..82b69b4 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.ctxt @@ -0,0 +1,14 @@ +#BlueJ class context +comment0.params=species\ name +comment0.target=Animal(java.lang.String,\ java.lang.String) +comment0.text=\n\ Create\ an\ animal\ of\ the\ specified\ species\ and\ with\ the\ specified\ name\n\ \n\ @param\ \ species\ a\ String\ specifying\ the\n\ type\ of\ animal\n\ @param\ \ name\ a\ String\ specifying\ the\ \n\ name\ of\ animal\n +comment1.params= +comment1.target=java.lang.String\ getSpecies() +comment1.text=\n\ Returns\ the\ species\ of\ the\ Animal\ object\n\ \n\ @return\ \ \ the\ species\ of\ animal,\ as\ a\ String\n +comment2.params= +comment2.target=java.lang.String\ getName() +comment2.text=\n\ Returns\ the\ name\ of\ the\ Animal\ object\n\ \n\ @return\ \ \ the\ name\ of\ animal,\ as\ a\ String\n +comment3.params= +comment3.target=java.lang.String\ toString() +comment3.text=\n\ Returns\ a\ string\ representing\ the\ Animal\ object.\ \ For\ a\ \n\ lion\ with\ name\ Leo\ it\ will\ return\ the\ String\ "Leo,\ a\ lion"\n\ \n\ @return\ \ \ a\ String\ representation\ of\ the\ animal\n +numComments=4 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.java b/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.java new file mode 100644 index 0000000..6f76a2d --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/Animal.java @@ -0,0 +1,59 @@ +/** + * class Animal simulates an animal and stores + * the species and name. + * + * @author D Newton + * @version Version 1, 1 November 2010 + */ +public class Animal +{ + // species of the animal e.g. lion, tiger + private String species; + // name of the animal e.g. Leo, Tommy + private String name; + + /** + * Create an animal of the specified species and with the specified name + * + * @param species a String specifying the + * type of animal + * @param name a String specifying the + * name of animal + */ + public Animal(String species, String name) + { + this.species = species; + this.name = name; + } + + /** + * Returns the species of the Animal object + * + * @return the species of animal, as a String + */ + public String getSpecies() + { + return species; + } + + /** + * Returns the name of the Animal object + * + * @return the name of animal, as a String + */ + public String getName() + { + return name; + } + + /** + * Returns a string representing the Animal object. For a + * lion with name Leo it will return the String "Leo, a lion" + * + * @return a String representation of the animal + */ + public String toString() + { + return name + ", a " + species; + } +} \ No newline at end of file diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/README.TXT b/Semester 2/Programming 2/Week 1/zoo-io-v3/README.TXT new file mode 100644 index 0000000..2bea2dd --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/README.TXT @@ -0,0 +1,12 @@ +------------------------------------------------------------------------ +This is the project README file. Here, you should describe your project. +Tell the reader (someone who does not know anything about this project) +all he/she needs to know. The comments should usually include at least: +------------------------------------------------------------------------ + +PROJECT TITLE: +PURPOSE OF PROJECT: +VERSION or DATE: +HOW TO START THIS PROJECT: +AUTHORS: +USER INSTRUCTIONS: diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.class b/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.class new file mode 100644 index 0000000..ec021b2 Binary files /dev/null and b/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.class differ diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.ctxt b/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.ctxt new file mode 100644 index 0000000..8c75b75 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.ctxt @@ -0,0 +1,35 @@ +#BlueJ class context +comment0.params= +comment0.target=Zoo() +comment0.text=\n\ Create\ an\ "empty"\ zoo\n +comment1.params=fileName +comment1.target=Zoo(java.lang.String) +comment1.text=\n\ Create\ a\ zoo\ and\ populate\ it\ using\ data\ from\ a\ text\ file\n +comment10.params=fileName +comment10.target=void\ readAnimalData(java.lang.String) +comment10.text=\n\ Reads\ animal\ data\ from\ a\ file\ and\ adds\ corresponding\ animals\ to\ the\ zoo\n\n\ @param\ \ \ fileName\ a\ String,\ the\ name\ of\ the\ \n\ \ \ \ \ \ \ \ \ \ text\ file\ in\ which\ the\ data\ is\ stored.\n\ \n\ @throws\ \ FileNotFoundException\n +comment2.params=animal +comment2.target=void\ storeAnimal(Animal) +comment2.text=\n\ Adds\ an\ animal\ to\ the\ zoo\n\n\ @param\ \ \ animal\ an\ Animal\ object,\ the\ animal\ to\ be\ added\n +comment3.params=listPosition +comment3.target=void\ showAnimal(int) +comment3.text=\n\ Shows\ an\ animal\ by\ printing\ it's\ details.\ \ This\ includes\n\ it's\ position\ in\ the\ collection.\n\n\ @param\ \ listPosition\ the\ position\ of\ the\ animal\n +comment4.params= +comment4.target=int\ numberOfAnimals() +comment4.text=\n\ Returns\ how\ many\ animals\ are\ stored\ in\ the\ collection\n\n\ @return\ \ \ the\ number\ of\ animals\ in\ the\ collection\n +comment5.params= +comment5.target=void\ showAllAnimals() +comment5.text=\n\ Displays\ all\ the\ animals\ in\ the\ collection\n\n +comment6.params=listPosition +comment6.target=void\ removeAnimal(int) +comment6.text=\n\ Remove\ an\ animal\ from\ the\ collection\n\n\ @param\ \ listPosition\ the\ position\ of\ the\ animal\n +comment7.params= +comment7.target=void\ populate() +comment7.text=\n\ Adds\ a\ pre-defined\ set\ of\ animals\ to\ the\ current\ collection\n\n +comment8.params= +comment8.target=void\ countAnimals() +comment8.text=\n\ Counts\ the\ number\ of\ lions,\ tigers\ and\ elephants\n\n +comment9.params=fileName +comment9.target=void\ writeAnimalData(java.lang.String) +comment9.text=\n\ Writes\ animal\ data\ to\ a\ file\n\n\ @param\ \ \ fileName\ a\ String,\ the\ name\ of\ the\ \n\ \ \ \ \ \ \ \ \ \ text\ file\ in\ which\ the\ data\ will\ be\ stored.\n\ \n\ @throws\ \ FileNotFoundException\n +numComments=11 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.java b/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.java new file mode 100644 index 0000000..e5f6a99 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/Zoo.java @@ -0,0 +1,194 @@ +import java.util.*; +import java.io.*; +/** + * class Zoo simulates storing animals in a collection. + * + * @author D Newton + * */ +public class Zoo +{ + private ArrayList animalCollection; + private int lionCount; + private int tigerCount; + private int elephantCount; + private int otherCount; + + /** + * Create an "empty" zoo + */ + public Zoo() + { + animalCollection = new ArrayList(); + lionCount = 0; + tigerCount = 0; + elephantCount = 0; + otherCount = 0; + } + + /** + * Create a zoo and populate it using data from a text file + */ + public Zoo(String fileName) throws FileNotFoundException + { + this(); + readAnimalData(fileName); + } + + /** + * Adds an animal to the zoo + * + * @param animal an Animal object, the animal to be added + */ + public void storeAnimal(Animal animal) + { + animalCollection.add(animal); + } + + /** + * Shows an animal by printing it's details. This includes + * it's position in the collection. + * + * @param listPosition the position of the animal + */ + public void showAnimal(int listPosition) + { + Animal animal; + if( listPosition < animalCollection.size() ) + { + animal = animalCollection.get(listPosition); + System.out.println("Position " + listPosition + ": " + animal); + } + } + + /** + * Returns how many animals are stored in the collection + * + * @return the number of animals in the collection + */ + public int numberOfAnimals() + { + return animalCollection.size(); + } + + /** + * Displays all the animals in the collection + * + */ + public void showAllAnimals() + { + System.out.println("Zoo"); + System.out.println("==="); + + int listPosition = 0; + while( listPositionlistPosition the position of the animal + */ + public void removeAnimal(int listPosition) + { + if( listPosition>=0 && listPosition it = animalCollection.iterator(); + while( it.hasNext() ) + { + Animal currentAnimal = it.next(); + String species = currentAnimal.getSpecies(); + if( species.equalsIgnoreCase("lion") ) + lionCount++; + else if( species.equalsIgnoreCase("tiger") ) + tigerCount++; + else if( species.equalsIgnoreCase("elephant") ) + elephantCount++; + else + otherCount++; + } + } + + /** + * Writes animal data to a file + * + * @param fileName a String, the name of the + * text file in which the data will be stored. + * + * @throws FileNotFoundException + */ + public void writeAnimalData(String fileName) throws FileNotFoundException + { + PrintWriter pWriter = new PrintWriter(fileName); + + for(Animal a: animalCollection) + { + String lineOfOutput = a.getName() + "," + a.getSpecies(); + pWriter.println(lineOfOutput); + } + pWriter.close(); + } + + /** + * Reads animal data from a file and adds corresponding animals to the zoo + * + * @param fileName a String, the name of the + * text file in which the data is stored. + * + * @throws FileNotFoundException + */ + public void readAnimalData(String fileName) throws FileNotFoundException + { + File dataFile = new File(fileName); + Scanner scanner = new Scanner(dataFile); + scanner.useDelimiter("[,\n]"); + + while( scanner.hasNext() ) + { + String name = scanner.next(); + name.trim(); + String species = scanner.next(); + species.trim(); + storeAnimal( new Animal(species, name) ); + } + scanner.close(); + } +} \ No newline at end of file diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.class b/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.class new file mode 100644 index 0000000..68f79e9 Binary files /dev/null and b/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.class differ diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.ctxt b/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.ctxt new file mode 100644 index 0000000..e34a293 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.params=file +comment0.target=ZooApp(java.lang.String) +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ ZooApp\n +numComments=1 diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.java b/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.java new file mode 100644 index 0000000..3e81d0f --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/ZooApp.java @@ -0,0 +1,22 @@ + +/** + * Write a description of class ZooApp here. + * + * @author (your name) + * @version (a version number or a date) + */ +import java.io.*; +public class ZooApp +{ + /** + * Constructor for objects of class ZooApp + */ + public ZooApp( String file ) throws FileNotFoundException + { + System.out.println( file ); + Zoo zoo = new Zoo(); + zoo.showAllAnimals(); + zoo.readAnimalData( "new_animals.txt" ); + zoo.showAllAnimals(); + } +} diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/animal_data.txt b/Semester 2/Programming 2/Week 1/zoo-io-v3/animal_data.txt new file mode 100644 index 0000000..077e4e6 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/animal_data.txt @@ -0,0 +1,10 @@ +Leo, Lion +Tommy, Tiger +Ollie, Elephant +Roland, Rat +Rudolph, Reindeer +Lenny, Lion +Nellie, Elephant +Tessa, Tiger +Hetty, Elephant +Leslie, Lion diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/new_animals.txt b/Semester 2/Programming 2/Week 1/zoo-io-v3/new_animals.txt new file mode 100644 index 0000000..0207d8e --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/new_animals.txt @@ -0,0 +1,3 @@ +Bobby, Bear +Andy, Aardvark +Polly, African Grey Parrot diff --git a/Semester 2/Programming 2/Week 1/zoo-io-v3/package.bluej b/Semester 2/Programming 2/Week 1/zoo-io-v3/package.bluej new file mode 100644 index 0000000..2e4ea95 --- /dev/null +++ b/Semester 2/Programming 2/Week 1/zoo-io-v3/package.bluej @@ -0,0 +1,51 @@ +#BlueJ package file +dependency1.from=Zoo +dependency1.to=Animal +dependency1.type=UsesDependency +dependency2.from=ZooApp +dependency2.to=Zoo +dependency2.type=UsesDependency +objectbench.height=76 +objectbench.width=686 +package.editor.height=400 +package.editor.width=560 +package.editor.x=774 +package.editor.y=277 +package.numDependencies=2 +package.numTargets=3 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +target1.editor.height=728 +target1.editor.width=900 +target1.editor.x=423 +target1.editor.y=237 +target1.height=50 +target1.name=ZooApp +target1.showInterface=false +target1.type=ClassTarget +target1.typeParameters= +target1.width=80 +target1.x=260 +target1.y=60 +target2.height=50 +target2.name=Animal +target2.showInterface=false +target2.type=ClassTarget +target2.typeParameters= +target2.width=80 +target2.x=100 +target2.y=60 +target3.editor.height=700 +target3.editor.width=900 +target3.editor.x=16 +target3.editor.y=254 +target3.height=50 +target3.name=Zoo +target3.naviview.expanded=true +target3.showInterface=false +target3.type=ClassTarget +target3.typeParameters= +target3.width=80 +target3.x=180 +target3.y=10