commit f54dd53c73ebe88cb0c99663e838573fc843cf75 Author: Christian Ohlsson Date: Thu Mar 5 13:43:17 2026 +0100 Startpunkten diff --git a/Java_Database/Book.java b/Java_Database/Book.java new file mode 100644 index 0000000..e34799a --- /dev/null +++ b/Java_Database/Book.java @@ -0,0 +1,20 @@ +/** +* This is a class called Book wich is +* a part of Element. So, each Element +* is a Book containing all the info +* about every Book. +* +* @author Christian Ohlsson, Karlstad university 1999 +* @version 1.0.0 +*/ +public class Book extends Element { + int MAXAUTHORS = 5; + String subject; + String title; + String allAuthors; + String []author = new String [MAXAUTHORS]; + String publisher; + String year; + +} + diff --git a/Java_Database/Element.java b/Java_Database/Element.java new file mode 100644 index 0000000..df709f1 --- /dev/null +++ b/Java_Database/Element.java @@ -0,0 +1,86 @@ +/** +* This is a class containing functios +* for the Elements in the list. +* +* +* @author Christian Ohlsson, Karlstad university 1999 +* @version 1.0.0 +*/ +public class Element { + Element suc; + +/** +* This is just the constructor. +*/ + public Element() { suc = null; } + +/** +* Returns the current Element in the list +*/ + public Element suc() { return suc; } + +/** +* This function inserts a new Element +* at the end of the List. +* It first checks out if the List is empty, +* i.e the first Element is null, and then +* the first Element is this Element. +* Otherwise, it inserts the new Element +* at the end of the List. +*/ + public void into(List theList) { + if (theList.first==null) + theList.first = theList.last = this; + else { + theList.last.suc = this; + theList.last = this; + } + suc = null; + } + +/** +* This function inserts a new Element at +* the beginning of the list. +* It first checks out if the List is empty, +* i.e the first Element is null, and then +* the first Element is this Element. +* Otherwise, the Element that were in the +* beginning, now is in second place and +* the new Element is in front of the List. +*/ + public void intoAsFirst(List theList) { + if (theList.first==null) { + theList.first = theList.last = this; + suc = null; + } + else { + suc = theList.first; + theList.first = this; + } + } + +/** +* This function deletes an Element in +* the List by traversing through the +* List until it gets to the Element +* that should be deleted. +*/ + public void out(List theList) { + Element prev = null; + Element e = theList.first; + while (e!=null && e!=this) { + prev = e; + e = e.suc; + } + if (e!=null) { + if (theList.last==this) + theList.last = prev; + if (theList.first==this) + theList.first = suc; + else + prev.suc = suc; + suc = null; + } + } +} + diff --git a/Java_Database/Linked.java b/Java_Database/Linked.java new file mode 100644 index 0000000..896c1c9 --- /dev/null +++ b/Java_Database/Linked.java @@ -0,0 +1,184 @@ +import java.awt.*; +import java.applet.*; +import java.io.*; +import java.util.*; + +/** +* This is the mainfile containing functions for +* this linked list with books. It also contains +* the constructor List that generates a new list +* called: myList. +* +* +* @author Christian Ohlsson, Karlstad university 1999 +* @version 1.3.4 +*/ +public class Linked { + static List myList = new List(); + +/** +* This function opens up a file and reads it +* line by line into a Stringbuffer. This +* buffer gets later on splitted into different +* categories by the StringTokenizer. The +* token I have choosed is the ; character, +* which separates the different fields apart +* in the file containing the data. After a +* line is read and tokenized, different +* variables is set in the node called myBook. +* Every new node, book, is inserted into myList. +*/ + public static int loadBooks(){ + String s, token = ";"; + int rows = 0; + try { + BufferedReader infil = new BufferedReader(new FileReader("fil.dat")); + do { + Book myBook = new Book(); + s = infil.readLine(); + StringTokenizer st = new StringTokenizer(s, token); + myBook.subject = st.nextToken(token); + myBook.title = st.nextToken(token); + setAuthors(myBook, st.nextToken(token)); + myBook.publisher = st.nextToken(token); + myBook.year = st.nextToken(token); + myBook.into(myList); + rows++; + }while(true); + } + catch(NoSuchElementException e1){System.err.println("No Such Element.");} + catch(FileNotFoundException e2){System.err.println("File Not Found.");} + catch(IOException e3){System.err.println("I/O Error.");} + catch(NullPointerException e4){} + System.out.println("This database contains " + rows + " books."); + return rows; + } + +/** +* This function reads a line from STDIN by using +* DataInputStream, and if the beginning character +* is an 'x', the program quits, if no character +* is given, the function restarts. +* If everything went OK, the search-string is sent +* to a function called inCatalog(String s) for +* further processing. +*/ + public static void search(int rows) { + DataInputStream in = new DataInputStream(new BufferedInputStream(System.in)); + String s; + try { + for (int i = 0; i < rows ; i++) { + System.out.print("\nBook register\n" + + "Press 'x' to exit.\n" + + "############################################\n" + + "Search for: "); + s = in.readLine(); + if(s.charAt(0) == 'x') + break; + else + inCatalog(s, rows); + } + } + catch(IOException e1) { e1.printStackTrace(); } + catch(StringIndexOutOfBoundsException e2) { + System.out.println("Enter a value, or press 'x' to exit"); + search(rows); + } + } + +/** +* This function calls the function myList.getElement +* and gets every node, book, in the database. +* It then compares every value of the node to the +* given String, and if it finds a match: the whole +* node is printed out along with the number of entries +* the search value found matches with. Otherwise, a +* message is printed out on the screen. +*/ + public static void inCatalog(String soktVarde, int rows) { + int found = 0; + try { + for (int i=0 ; i 0) + System.out.println("There were " + found + + " entries in the database about " + + soktVarde + "."); + else + System.out.println("There's no information about " + + soktVarde + " in this database"); + } +/** +* This function recives an array of authors and a +* search string. If then loops through the array +* of authors and tries to locate the search string +* in the array. Because I use indexOf for the search, +* the author Kernighan A. B will be found if the search +* string is Kerni, rnighhan, or n A. B. +* It returns true if the author was found, otherwise false. +*/ + public static boolean isAuthor(String author[], String soktVarde) { + try { + int i=0; + while(author[i] != null) { + if(author[i].indexOf(soktVarde) >= 0) + return true; + i++; + } + } + catch(NullPointerException e4){System.out.println("Null ptr in isAthor");} + return false; + } + +/** +* This function recieves a Book, and a String +* containing all of the authors of a Book. It +* the splits up the String, using the StringTokenizer +* and puts the different authors in different +* places in the array of authors of each Book. +*/ + public static void setAuthors(Book myBook, String inString) { + String token = ","; + int i=0; + myBook.allAuthors = inString; + try { + StringTokenizer st = new StringTokenizer(inString, token); + while(st.hasMoreTokens()) { + myBook.author[i] = st.nextToken(token); + i++; + } + } + catch(NoSuchElementException e1){System.err.println("No Such Element.");} + catch(NullPointerException e4){System.err.println("Null Pointer In setAuthors.");} + } + +/** +* The main function really does'nt do much. +* It just calls the functions loadBooks() +* and gets the number of Books in the database +* from there and then calls the search-function +* with the number of Books as a parameter. +*/ + public static void main(String args[]) { + int rows = loadBooks(); + search(rows); + } +} + + diff --git a/Java_Database/List.java b/Java_Database/List.java new file mode 100644 index 0000000..fdda37c --- /dev/null +++ b/Java_Database/List.java @@ -0,0 +1,70 @@ +/** +* This class contains the linked list. +* It also contains the constructor, wich +* generates a new list called myList +* +* @author Christian Ohlsson, Karlstad university 1999 +* @version 1.0.0 +*/ +public class List { + Element first, last; + +/** +* This is the constructor of the list. +* What it basically do is to set +* the two Elements constructed before +* to null. +*/ + public List() { first = last = null; } + +/** +* This function returns the first Element +* in the list. +*/ + public Element first() { return first; } + +/** +* This function returns the last Element +* in the list. +*/ + public Element last() { return last; } + +/** +* If the first element in the List is null, +* it returns true, that is, there's no Elements +* in the List. +*/ + public boolean empty() { return first==null; } + +/** +* This function recives a number and it traverses +* though the List until that number is reached +* and then returns the Element on that location +*/ + public Element getElement(int number) { + Element e = first; + int antal = 0; + while (antal= xsize) + xspeed = -xspeed; + + yOffset-=yspeed; + if(yOffset <= 5) + yspeed = -yspeed; + + if(yOffset+helloTextHeight >= ysize) + yspeed = -yspeed; + + // Copy the backbuffer to the screen + g.drawImage(backBuffer, 0, 0, this); + } + public void update(Graphics g) { + paint(g); + } + +} + diff --git a/Java_Intro/view_it.html b/Java_Intro/view_it.html new file mode 100644 index 0000000..21d84e5 --- /dev/null +++ b/Java_Intro/view_it.html @@ -0,0 +1,15 @@ + + Java Lab1 + + +Java Lab 1 +
+ + + + +
+Source + + + diff --git a/Lisp_Database/db.lisp b/Lisp_Database/db.lisp new file mode 100644 index 0000000..047d2bc --- /dev/null +++ b/Lisp_Database/db.lisp @@ -0,0 +1,102 @@ +; ========================================== +; # Laboration 2 i Programspråk # +; # LISP # +; # ======================================== # +; # Christian Ohlsson # +; # Karlstads universitet # +; # 1999-05-19 # +; # ========================================= + +;Main function which starts the program +;Prints welcome-msg and ask for yor choice +(defun run () + (format t "~% Welcome to the database ") + (format t "~% ======================= ") + (format t "~% Press s to search, ") + (format t "~% or 'x' to exit. ") + (format t "~% ======================= ") + (format t "~% ") + (setq val (read)) + (cond ((equal val 's) (dosearch (getdb)) (run)) + ((equal val 'x) (format t "~%Exiting") ) + (t (format t "~% That's not a valid option") (run)) + ) +) +;Prints out each found book on the screen +(defun printbook(book) + (when book + (format t "~% Subject : ~a" (first book)) + (format t "~% Title : ~a" (second book)) + (format t "~% Publisher : ~a" (third book)) + (format t "~% Year : ~a" (fourth book)) + (printauthors (fifth book)) + (format t "~% ") + (format t "~% ------------------------------------------------") + ) +) + +;Asks for the search value and then calls +;the search-procedure +(defun dosearch (library) + (format t "~% Enter search: ") + (setq value (read-line t)) + (getit library value) +) + +;Prints out the authors of each book +(defun printauthors(authors) + (when authors + (format t "~% Author : ~a"(first authors)) + (printauthors (rest authors)) + ) +) + +;Gets the subject, title, publisher, year and author +;for each book found +(defun getbook(book value) + (cond + ((integerp(search value (first book))) (printbook book)) + ((integerp(search value (second book))) (printbook book)) + ((integerp(search value (third book))) (printbook book)) + ((integerp(search value (fourth book))) (printbook book)) + ((getauthor (fifth book) value) (printbook book)) + ) +) + +;Searches recursivly throuh the library and +;lets getbook see if it's a match, +;and the do the same with the next book. +(defun getit(library value) + (when library + (getbook (first library) value) + (getit(rest library) value) + ) +) + +;Checks if it is a author +(defun getauthor (authors value) + (when authors + (cond + ((integerp(search value (first authors))) t) + (t (getauthor (rest authors) value)) + ) + ) +) + +;Defines our database. +(defun getdb () + (setf library ' + ( + ( "C Lang" "From C to C An Intro to ANSI Standard C" "Harcourt Brace Jovanovic" "1989" ("Gardner J.") ) + ( "Compilers" "Compilers Principles Techniques and Tools" "Addison Wesley" "1986" ( "Ullman J.D." "Aho A.V." "Sethi R.") ) + ( "Compilers" "Compiler Design in C" "Prentice Hall" "1990" ( "Holub A.I.") ) + ( "Databases" "An Introduction to Database Systems" "Addison Wesley" "1995" ( "Date C.J.") ) + ( "Databases" "The Theory of Relational Databases" "Computer Science Press" "1983" ( "Maier D.") ) + ( "HCI" "Human-Computer Interaction" "Prentice Hall" "1993" ( "Dix A." "Finlay J." "Abowd G." "Beale R.") ) + ( "Prog Langs" "Programming Languages Concepts & Constructs" "Addison Wesley" "1996" ( "Sethi R.") ) + ( "Prog Langs" "Concepts of Programming Languages" "Addison Wesley" "1996" ( "Sebesta R.W.") ) + ( "C Lang" "The C Programming Language" "Prentice Hall" "1988" ( "Kernighan B.W." "Ritchie D.M.") ) + ( "Prog Langs" "Programming Languages Principles and Practice" "PWS Publishing" "1993" ( "Louden K.C." )) + ) + ) +) diff --git a/Lisp_Database/read_me b/Lisp_Database/read_me new file mode 100644 index 0000000..feb2e1a --- /dev/null +++ b/Lisp_Database/read_me @@ -0,0 +1,14 @@ +Readme fil för Lisp Lab i Programspråk +--------------------------------------------- + +Sökbar databas med böcker. + +Denna lab är provkörd och klar. +Starta Lisp med: gcl +skriv: + (load "db.lisp") + (run) +för att köra programmet. + +--------------------------------------------- +Christian Ohlsson. di7chro@cse.kau.se diff --git a/Prolog_Database/db.pl b/Prolog_Database/db.pl new file mode 100644 index 0000000..100b47d --- /dev/null +++ b/Prolog_Database/db.pl @@ -0,0 +1,49 @@ +/********************************/ +/* Laboration 4 i Programspråk */ +/* Prolog */ +/********************************/ +/* Christian Ohlsson */ +/* Karlstads universitet 990525 */ +/********************************/ + + +book('C Lang', 'The C Programming Language', ['Kernighan B.W.', 'Ritchie D.M.'], 'Prentice Hall', '1988'). +book('C Lang', 'From C to C: An Intro to ANSI Standard C', ['Gardner J.'], 'Harcourt:Brace Jovanovic', '1989'). +book('Compilers', 'Compilers: Principles Techniques and Tools', ['Ullman J.D.', 'Aho A.V.', 'Sethi R.'], 'Addison Wesley', '1986'). +book('Compilers', 'Compiler Design in C', ['Holub A.I.'], 'Prentice Hall', '1990'). +book('Databases', 'An Introduction to Database Systems', ['Date C.J.'], 'Addison Wesley', '1995'). +book('Databases', 'The Theory of Relational Databases', ['Maier D.'], 'Computer Science Press', '1983'). +book('HCI', 'Human-Computer Interaction', ['Dix A.', 'Finlay J.', 'Abowd G.', 'Beale R.'], 'Prentice Hall', '1993'). +book('Prog Langs', 'Programming Languages Concepts & Constructs', ['Sethi R.'], 'Addison Wesley', '1996'). +book('Prog Langs', 'Concepts of Programming Languages', ['Sebesta R.W.'], 'Addison Wesley', '1996'). +book('Prog Langs', 'Programming Languages Principles and Practice', ['Louden K.C.'], 'PWS Publishing', '1993'). + +run :- write_ln(' '), + write_ln(' ========================================== '), + write_ln(' Welcome to the database. '), + write_ln(' Type search(searchstring). to search '), + write_ln(' ========================================== '), + write_ln(' '). + +subject(X) :- book(X,T,A,P,Y), printbook(X,T,A,P,Y), fail. +title(X) :- book(S,X,A,P,Y), printbook(S,X,A,P,Y), fail. +author(X) :- book(S,T,A,P,Y), member(X,A), printbook(S,T,X,P,Y), fail. +publisher(X) :- book(S,T,A,X,Y), printbook(S,T,A,X,Y), fail. +year(X) :- book(S,T,A,P,X), printbook(S,T,A,P,X), fail. + +search(X) :- subject(X). +search(X) :- title(X). +search(X) :- author(X). +search(X) :- publisher(X). +search(X) :- year(X). + +member(X,[X|_]). +member(X,[_|Y]) :- member(X,Y). + +printbook(S,T,A,P,Y) :- write('Subject: '), write_ln(S), + write('Title: '), write_ln(T), + write('Author: '), write_ln(A), + write('Publisher: '), write_ln(P), + write('Year: '), write_ln(Y), + write_ln(' '). + diff --git a/Prolog_Database/read_me b/Prolog_Database/read_me new file mode 100644 index 0000000..29e513b --- /dev/null +++ b/Prolog_Database/read_me @@ -0,0 +1,14 @@ +Readme fil för Prolog Lab i Programspråk +--------------------------------------------- + +Sökbar databas med böcker. + +Denna Lab är provkörd och klar. +Starta SWI Prolog med: pl +Skriv: + ['db.pl']. + run. +för att köra programmet. + +--------------------------------------------- +Christian Ohlsson. di7chro@cse.kau.se