Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project Outcomes - Develop a Java program that: creates a user designed class us

ID: 3681422 • Letter: P

Question

Project Outcomes - Develop a Java program that:

creates a user designed class

uses proper design techniques including reading UML Class Diagrams

reads input from the keyboard using a Scanner Object and its methods

uses selection (if and if else) statements

uses iteration (while, do while or for) statements

uses String comparison methods.

follows standard acceptable programming practices.

handles integer overflow errors

Background Information:

The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class diagram, which are used to depict the attributes and behaviors of a class. A basic class diagram (as shown in the figure below) has three components. The first is the class name. The second component includes the class's attributes or fields. Each attribute is followed by a colon (:) and its data type. The third component includes the class's behaviors or methods. If the method takes parameters, their types are included in parentheses. Each behavior is also followed by a colon (:) and its return type. If the return value of a method is void, the return type can be omitted. For more information on the UML, refer to HYPERLINK "http://www.uml.org/" http://www.uml.org/.

Project Requirements:

This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java.

Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password.

The Encryption class: (Additionally See UML Class Diagram)

Instance Variables

Key – Integer representing the password key

encryptedPassword – String representing the encrypted password.

Constructors

Default (no parameter) Constructor – sets all instance variables to a default value

Parameterized Constructor

Takes in a key and the clear text password as parameters

Set the instance variable key from the associated parameter

Call the encrypt method to encrypt the clear text password.

Methods

encrypt

Takes in a clear text password as a parameter

Uses the instance variable key to encrypt the password.

Stores the encrypted password in the encryptedPassword instance variable

isValidPassword

Take in a clear text password as a parameter

Compares the clear text password with the stored encryptedPassword (Hint you must first encrypt the clear text password parameter)

Returns true if the passwords match, false if they don’t.

getEncryptedPassword – returns the encrypted password.

setKey – takes in a new key as a parameter and sets the instance variable key to that value.

getKey – returns the instance variable: key

toString – returns a nicely formatted String in the form below use the getKey and getEncryptedPasswordmethod to retrieve those values, do not use the instance variable directly.

Example: The encrypted password is UeiY3$2Spw. The used to generate this password is 3.

Encryption

Password Class

This class is very similar to Project 3 however there is some additional error handling and the use of theEncryption class.

Ask the user for a password

Check to ensure the password is a least 8 characters long. If it is not, then print the following error message and ask the user to enter a password that is at least 8 characters, continue asking until they enter a valid password:

The password must be at least 8 characters long, your password is only X characters long. (X is the length of the current password)

Ask the user a number between 1 and 10 (Inclusive) that will be used as the encryption key. If it is not between 1 and 10, then print the following error message and ask the user to enter a key that is between 1 and 10continue asking until they enter a valid password.

The key must be between 1 and 10, you entered is X. (X is the number entered)

Create two objects of the Encryption class:

Create the first Encryption class object using the default constructor

Create the second Encryption class object using the parameterized constructor (pass the password and key entered by the user as its parameters)(Remember the parametrized constructor calls the encryption method within the Encryption class)

Call the second object’s toString and display the results.

Test the encrypt method

Prompt the user to enter their password

Calls the isValidPassword method using this clear text password as its parameter

Display a message indicating the results of password validation.

Test all other methods of the Encryption class that haven’t already been tested, such as setKey.

Prompt the user if they would like to run the program and if so restart the program.

Encryption Algorithm

Implement a simple shift cipher.

A shift cipher is a form of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with shift of 3, A would be replaced by D, B would become E, and so on.

The shift for this program will be the key entered by the user.

The password may be any of the characters in the HYPERLINK "http://www.asciitable.com/" ASCII table from character 33 the exclamation point ‘!’ to character 122 the lower case ‘z’.

If the shift cause the character to be greater than 122, the shift will continue starting with character 33.

Example:

If the user entered 8 as the key and a letter in the password is lower case ‘x’ (char 120) a shift of 8 would result in the character ‘&’ (char 38).

Include javadoc class comment following Project Comment Template on the content page.

The project requires two files to be turned in - Password.java and Encrytion.java (the source code of yourPassword program)

Be sure to follow the Programming Project Submission Instructions posted by your instructor on the elearning site.  The submission requirements are part of the grading for this assignment.

Encryption

Password Class

Explanation / Answer

Answer:

/***BlogEntry.java****/

import java.io.*;

import java.util.*;

// class BlogEntry

public class BlogEntry

{

private String username;

private Date dateOfBlog;

private String blog;

public BlogEntry()

{

username="";

dateOfBlog=new Date();

blog="";

}

public BlogEntry(String uName, Date bDate, String textBlog)

{

username=uName;

dateOfBlog=bDate;

blog=textBlog;

}

//ACCESSOR METHODS

public String getUsername( )

{

return username;

}

public Date getDateOfBlog( )

{

return dateOfBlog;

}

public String getBlog( )

{

return blog;

}

//MUTATOR METHODS

public void setUsername(String uName )

{

username=uName;

}

public void setDateOfBlog(Date bDate)

{

dateOfBlog=bDate;

}

public void setBlog(String textBlog)

{

blog=textBlog;

}

//getSummary()

public String getSummary()

{

String blogSummary="";

int countBlogWord=0;

int bStart=0;

int bpos;

bpos=blog.indexOf(" ");

while(bpos!=-1&&countBlogWord<10)

{

blogSummary+=blog.substring(bStart,bpos);

blogSummary+=" ";

bStart=bpos+1;

bpos=blog.indexOf(" ",bpos+1);

countBlogWord+=1;

}

return blogSummary;

}

//toString() return the blog details

public String toString()

{

String nSt=null;

nst= "AUTHOR: " + this.getUsername() + " " + "Date posted: " + this.getDateOfBlog() + " " + "Text body: " + this.getBlog();

return nSt;

}

}

// BlogEntryTester.java

public class BlogEntryTester

{

public static void main(String[] args)

{

BlogEntry obj1=new BlogEntry();

BlogEntry obj2=new BlogEntry("John",new Date(4,15,2013),"I went to The Masters last week, it was fantastic");

System.out.println("Blog Object 1:");

System.out.println(obj1.toString());

System.out.println("Blog Object 2:");

System.out.println(obj2.toString());

System.out.println(obj1.getSummary());

System.out.println(obj2.getSummary());

//READING FROMFILE

File blogFile=new File("test.dat");

try

{

Scanner rFile=new Scanner(blogFile);

while(rFile.hasNextLine())

{

rFile.useDelimiter(",");

String aName=rFile.next();

int m=Integer.parseInt(rFile.next());

int d=Integer.parseInt(rFile.next());

int y=Integer.parseInt(rFile.next());

String textBlog=rFile.next();

BlogEntry obj3;

//testing if Date is valid

if(dateOK(m,d,y)

{

Obj3=new BlogEntry(aName,new Date(m,d,y),textBlog);

}

else

Obj3=new BlogEntry(aName,new Date(),textBlog);

//printing the blogObject created fromfile

System.out.println(obj3.toString());

}

}

catch(Exception exp)

{

exp.printStackTrace();

}

}//main end

}//driver class ends