DOC PREVIEW
WVU CS 110 - Outside Class Programming Assignment I

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 110 Introduction to Computer Science Outside Class Programming Assignment I Due: At the Start of Class Friday Sept. 26, 2008 Encrypting Four Letter Words You are to write a program which encrypts four letter words (clean words are also acceptable :-)) by using character replacement. Your program should accept a four letter word from the user, and randomly generate letters to replace each letter in the word thereby encrypting the word. To do this you will need the String functions of replace and charAt. From the Math library you will need the function random. This program will also require type conversions. Plan: Input the word Generate a number between 97 and 122 To do this generate an integer between 0-25 then add 97 to it Replace the first character (recall this is character 0) in the word with generated character Repeat the generate and replace for characters 1, 2, and 3 Display the encrypted word. You are to turn in at the start of lecture a gnulisting of your program and email a copy of your source to your lab instructor (and *only* your lab instructor) by 8am on Friday Sept. 26, 2008. --- Begin Jumble.java --- 1: 2: import java.util.Scanner; 3: import java.lang.Math; 4: 5: public class Jumble 6: { 7: 8: public static void main(String [] agrs) 9: { 10: 11: String word; 12: int length; 13: int changeIt; 14: char let, relet; 15:16: Scanner sc = new Scanner (System.in); 17: 18: System.out.print ("enter a 4 letter word: "); 19: word = sc.next(); 20: 21: length = word.length(); 22: 23: changeIt = (int) (Math.random()*26) + 97; 24: 25: System.out.println(" the random char is: " + changeIt); 26: 27: let = (char) changeIt; 28: 29: relet = word.charAt(0); 30: 31: word = word.replace(relet, let); 32: System.out.println("the encrypted word is: " + word); 33: changeIt = (int) (Math.random() *26) + 97; 34: System.out.println(" the random char is: " + changeIt); 35: 36: let = (char) changeIt;; 37: 38: relet = word.charAt(1); 39: 40: word = word.replace(relet, let); 41: System.out.println("the encrypted word is: " + word); 42: changeIt = (int) (Math.random() *26) + 97; 43: System.out.println(" the random char is: " + changeIt); 44: 45: let = (char) changeIt;; 46: 47: relet = word.charAt(2); 48: 49: word = word.replace(relet, let); 50: System.out.println("the encrypted word is: " + word); 51: changeIt = (int) (Math.random() * 26) + 97; 52: System.out.println(" the random char is: " + changeIt); 53: 54: let = (char) changeIt;; 55: 56: relet = word.charAt(3); 57: 58: word = word.replace(relet, let); 59: 60: System.out.println("the encrypted word is: " + word); 61: } 62: } Compilation Successful. --- End Jumble.java ---CS 110 Introduction to Computer Science Outside Class Programming Assignment I Due: At the Start of Class Wednesday Feb. 11, 2009 Write complete JAVA Programs to solve #19 on page 117 and the following problem. In a new computer assisted board game moves are determined by selecting a random number. However, players can influence their moves by taking a risk. The player selects a random number, n, between 1-10. The computer then generates a random integer, r, from 1 to 10. The player’s move is then (r-n+1)*n. A cautious player selects 1 and always moves forward. An ambitious player selects higher numbers and may move forward or backwards. Write a program to determine one move in the game. Display the computer’s number and the move. On or before Wednesday Feb 11, 2009 you are to create a compiled listing of both programs using gnulist javac programName | a2ps or gnulist javac programName > programName.txt and then print the file programName.txt and turn in the hardcopy at the start of class. You are to email the source code to both programs to your lab instructor (and only your lab instructor) prior to 10am Wednesday Feb 11. --- Begin Game.java --- 1: /**Sample Program CS 110 Solution to 2: * Outside lab Assignment I 3: * Spring 2009 4: * */ 5: 6: 7: import java.util.Scanner; 8: import java.lang.Math; 9: 10: public class Game 11: { 12: public static void main(String [] args) 13: { 14: Scanner sc = new Scanner(System.in); 15:16: int randNum, playerNum, move; 17: 18: System.out.print("Enter a number between 1 and 10: "); 19: playerNum= sc.nextInt(); 20: 21: randNum = (int) (Math.random()*10)+1; 22: move = (randNum-playerNum+1)*playerNum; 23: 24: System.out.println("The random number generated was: " + randNum); 25: System.out.println("The move resulting was: " + move); 26: } 27: } 28: Compilation Successful. --- End Game.java --- --- Begin Page117_19.java --- 1: /**Sample Program CS 110 Solution to 2: * Outside lab Assignment I 3: * Spring 2009 4: * */ 5: 6: 7: import java.util.Scanner; 8: 9: public class Page117_19 10: { 11: public static void main(String [] args) 12: { 13: Scanner sc = new Scanner(System.in); 14: 15: String first, second, third; 16: 17: System.out.print("Enter the first string: "); 18: first = sc.nextLine(); 19: System.out.print("Enter the second string: "); 20: second = sc.nextLine(); 21: System.out.print("Enter the third string: "); 22: third = sc.nextLine(); 23: 24: System.out.println("The six permutations are"); 25: System.out.println(first+second+third); 26: System.out.println(first+third+second); 27: System.out.println(second+third+first); 28: System.out.println(second+first+third); 29: System.out.println(third+second+first); 30: System.out.println(third+first+second); 31: } 32: }


View Full Document

WVU CS 110 - Outside Class Programming Assignment I

Download Outside Class Programming Assignment I
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Outside Class Programming Assignment I and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Outside Class Programming Assignment I 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?