Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

URGENT Please Help: **JAVA Assignment 10 - Intro** This assignment will focus on the use of classes, objects, object/instance variables, constructor methods, class methods, object/instance

URGENT Please Help: **JAVA Assignment 10 - Intro**

This assignment will focus on the use of classes, objects, object/instance variables, constructor methods, class methods, object/instance methods, and inheritance.

Follow the directions below to submit Assignment 10:

1. You will create the EncryptString class which will inherit the AnyString class (code included below). The EncryptString class should be coded as follows:

a. Create a new class named EncryptString in a separate file. The EncryptString class should inherit the AnyString class. The EncryptString class should be a file in the same folder as the AnyString class.

b. Create two constructors for the EncryptString class. Each of the constructors should match one of the constructor methods in the AnyString class.

c. Add a object/instance method named encryptString() that accepts no arguments and returns a String. This method should encrypt the object/instance variable. This method will be a modified version of the method created for the previous assignment.

d. Add a class/static method named encryptString() that accepts a String argument and returns an encrypted String object. This method can be found in a previous assignment.

e. Add a class/static method named decryptString() that accepts an encrypted String argument and returns a decrypted String object. This methods can be found in a previous assignment.

2. Add a main() method to theEncryptString class that will contain the following:

a. You should input a string.

b. Create an object of the EncryptString class.

c. Call all the methods in the EncryptString class, verify that they work, and display the results.

d. Create a character array and create an object of the EncryptString class.

e. Call all the methods in the EncryptString class, verify that they work, and display the results.

***Code to be modified included below***

import java.util.*;

class AnyString { String str;

AnyString(String s1) { str = s1; } //constructor method AnyString(char arr[]) { str = new String(arr); } //accept no arguments and return the object/instance variable public String toString() { return str; } //accept AnyString object & return true if argument contains object/instance variable value that is equal to the object/instance public boolean equals(AnyString anyString) { return str.equals(anyString.getString()); } //accept no arguments & return true if object/instance variable is all letters or false if not all letters public boolean isLetters() { for(int i = 0; i < str.length(); ++i) { if(!Character.isLetter(str.charAt(i))) return false; } return true; } //accept no arguments and return true if the object/instance variable is all numbers or false if not all numbers public boolean isNumeric() { for(int i = 0; i < str.length(); ++i) { if(!Character.isDigit(str.charAt(i))) return false; } return true; }

String getString() { //returns the entered string value return str; }

String lowercase() { //returns entered string in lowercase return str.toLowerCase(); }

String uppercase() { //returns entered string in uppercase return str.toUpperCase(); }

int getLength() { //returns length of entered string return str.length(); } public static void main(String[] args) { Scanner in = new Scanner(System.in); String str; System.out.print("Enter a string: "); str = in.next(); AnyString anyString = new AnyString(str); System.out.println("toString: " + anyString.toString()); System.out.println("equals: " + (anyString.equals(anyString))); System.out.println("isNumeric: " + anyString.isNumeric()); System.out.println("isLetters: " + anyString.isLetters()); //calling method AnyString anyString1 = new AnyString(new char[]{'a', 'b', 'c'}); System.out.println("toString: " + anyString1.toString()); System.out.println("equals: " + (anyString1.equals(anyString1))); System.out.println("isNumeric: " + anyString1.isNumeric()); System.out.println("isLetters: " + anyString1.isLetters()); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions