Posts

Showing posts with the label java

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...

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...

Double Transposition in Java

/* Dalibor Labudovic*/ /* not stable */ package doubletransporition; import java.io.*; import java.util.*; class NewDoubleTransposition {     public static void main(String args[])     {         NewEncryptAndDecrypt ned=new NewEncryptAndDecrypt();         ned.input();     } } class NewEncryptAndDecrypt {     Scanner sc=new Scanner(System.in);     void input()     {         int ch;         do         {             System.out.println("\n\t\t*****ENTER*****");             System.out.println("\t1.Encrypt");             System.out.println("\t2.Decrypt");             System.ou...

Vigenere Cipher in Java

/* Dalibor Labudovic */ /* Not 100% stable but work ok*/ package cs3550; import java.util.Scanner; public class vigenerecipher {     public static void main(String[] args) {         @SuppressWarnings("resource")         Scanner input = new Scanner(System.in);                         System.out.println("Encyption...");         System.out.println("Enter Pass Phrase: ");         String phrase = input.nextLine();         System.out.println("Enter plain Text: ");         String plain = input.nextLine();         System.out.print("Here is the encryption: ");         String enc = encrypt(plain, phrase);     ...

CS 3401 Homeworks 3

Homework # 3 Exercise #1 Write an implementation of the Rational.java class and that uses BigInteger for numerator and denominator. Write a test driver class called TestRational.java that creates at least two Rational numbers (using BigIntegers as the arguments to the Rational constructor) and then adds, subtracts, multiplies and divides the Rational numbers and tests them for equality, printing out the results of each of these operations. Be sure your programs compile and run without error. Review the Submission Requirements document and make sure your submission meets those requirements. Please also review the Grading Guidelines for an indication of general guidelines used in evaluating your assignments. Deliverables Turn in the files:     Rational.java     TestRational.java ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Rational.java package assignment3; import java.math.BigIntege...

CS3401 Practice Quiz 2 Part 3

Image
Introduction to Java Programming Introduction to Java Programming, Ninth Edition, Y. Daniel Liang Chapter 24 Developing Efficient Algorithms Please send suggestions and errata to Dr. Liang at y.daniel.liang@gmail.com . Indicate which book and edition you are using. Thanks! Section 24.2 Measuring Algorithm Efficiency Using Big O Notation 24.1   Estimating algorithm efficiency is ________ A. to measure their actual execution time. B. to estimate their execution time. C. to estimate their growth function. Your answer is correct 24.2   An input that results in the shortest execution time is called the _____________. A. best-case input B. worst-case input C. average-case input Your answer is correct 24.3   Why is the analysis often for the worst case? A. Best-case is not representative. B. Worst-case is not representative, but worst-case analysis is very useful. You can show that the algo...

CS3401 Practice Quiz 2 Part 2

Image
Introduction to Java Programming Introduction to Java Programming, Ninth Edition, Y. Daniel Liang Chapter 10 Thinking in Objects Please send suggestions and errata to Dr. Liang at y.daniel.liang@gmail.com . Indicate which book and edition you are using. Thanks! Section 10.2 Immutable Objects and Classes 10.1   Which of the following statements are true about an immutable object? A. The contents of an immutable object cannot be modified. B. All properties of an immutable object must be private. C. All properties of an immutable object must be of primitive types. D. An object type property in an immutable object must also be immutable. E. An immutable object contains no mutator methods. Your answer is correct Section 10.3 Scope of Variables 10.2   What is the printout for the first statement in the main method? public class Foo {   static int i = 0;   static int j = 0;  ...