Posts

Showing posts from July, 2014

Caesar Cipher in Java

Credit goes to Musa Mohammed for his help. import java.util.Scanner; public class CaesarCipher { public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz"; public static String encrypt(String plain_Text,int shiftKey) { plain_Text = plain_Text.toLowerCase(); String cipherText=""; for(int i=0;i<plain_Text.length();) { if(plain_Text.charAt(i) == ' ') { cipherText += plain_Text.charAt(i); i++; } else { int charPosition = ALPHABET.indexOf(plain_Text.charAt(i)); int keyVal = (shiftKey+charPosition)%26; char replaceVal = ALPHABET.charAt(keyVal); cipherText += replaceVal; i++; } } return cipherText; } public static String decrypt(String cipherText, int shiftKey) { cipherText = cipherT…

Timer/Count Down in standard C

#include <stdio.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> #include <setjmp.h> static void sig_alarm (int signo); void err_sys (const char* message); static jmp_buf alarm_jmp; int main (int argc, char* argv[]) { int time_left = 10; if (signal (SIGALRM, sig_alarm) == SIG_ERR) err_sys ("alarm signal error"); alarm (1); if (sigsetjmp (alarm_jmp, 1) != 0) { time_left--; if (time_left == 0) { printf ("BOOM\n"); exit(0); } else { printf ("%d\n", time_left); alarm (1); } } while (1); exit(0); } static void sig_alarm (int signo) { siglongjmp (alarm_jmp, 1); } void err_sys (const char* message) { printf ("%s\n", message); exit (0); }

CS3401 HW 7

package trees; /** Course: CS 3401  * Section: 01  * Name: Dalibor Labudovic  * Professor: Prof. Shaw  * Assignment #: Homework #7  */  import java.math.BigDecimal; import java.util.*; //******************************************************************** // Evaluates a given expression by first converting it to a // Postfix Stack and then to an Expression Tree and then // evaluating the Expression Tree //********************************************************************  public class EvaluateExpressionTree {  public static void main(String[] args) {  Scanner input = new Scanner(System.in);  System.out.println("Enter an equation in infix notation: " + "[Ex: 10+6/3 ]");  String expression = input.nextLine();  input.close();  try {  System.out.println("Result = " + evaluateExpressionTree(expression).stripTrailingZeros().toPlainString());  }  catch (Exception ex) {  System.out.println("Bad expression");  }  }  // Converts a…

CS3401 Homework Assignment 8

Image
Homework Assignment #8 Exercise #1 Modify the DisplayBinaryTree.java class given out in Sample Code #8, to add three new buttons: "Show Inorder", "Show Preorder", and "Show Postorder". Each of these buttons when pressed must pop up a JOptionPane message dialog box that shows the values in the tree listed in the proper order for the ordering controlled by that button. For instance, if the "Show Inorder" button is pressed for the following tree:

Then a pop up dialog will show something like:

And if the user had pressed the "Show Preorder" button, a pop up dialog will show something like the following:

And if the user had pressed the "Show Postorder" button, a pop up dialog will show something like the following:

You will need the following three classes in your class hierarchy in order to get your program working (they are the same ones from the last assignment, and you should not change them at all):
Tree.java (…

CS3401 Quiz 6

Image
Question 15 / 5 points Which of the following are the three major categories of Java Collections? lists, sets, maps hash tables, hash maps, hash sets arraylists, linkedlists, vectors trees, lists, maps Question 25 / 5 points A collection that does not impose a positional order on its elements, and does not allow duplicates is called which of the following? A hashmap A linkedlist A vector A set Question 35 / 5 points A collection whose elements are pairs of keys and values is called which of the following? An iterator A map

KSU CS Program Books in PDF

Books Disclaimer: These are not owned by me, i dont not own this material. Use with copy right caution.

CS3401 Assignment 6

Homework Assignment #6 Exercise #1 Write an implementation of a generic version of MyLinkedList.java and its methods. In addition, you must modify the MyLinkedList class in the following ways while maintaining a generic implementation of this class:
Make the MyLinkedList class a doubly linked list. This means adding to the Node inner class the following field which also starts off equal to null: public Node prev; As the program works now, the "list" field in the main MyLinkedList class always points to the first element in the linked list. Add a "last" field as well that always points to the last element. public Node last; Note: this field is not stored in the Node inner class.
Modify the toString() method of the MyLinkedList class so that it returns a string consisting of all of the elements of the list from first to last on one line separated by commas with "<" in the front and ">" at the back, and then that one line is…

Google I'm Feeling Lucky Hidden Feature

Image
I'm Feeling Lucky Hidden Feature With your cursor, hover over "I'm Feeling Lucky" button, and it will change to different "I'm Feeling" options. See images below.


CS4150 Assignemt 4 Ada Book

There are 4 files:
1) assign4.gpr
2) books.adb
3) books.ads
4) test_book.adb


Source Code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assign4.gpr
----------------------------------------------------------------------------------------------------------------------------------

project Assign4 is

   for Source_Files use ("books.adb", "books.ads", "test_book.adb");
   for Main use ("test_book.adb");

end Assign4;
---------------------------------------------------------------------------------------------------------------------------------