Question

Loops | Methods | Arrays(programming language java) in software (ATOM) Write a toolkit that includes some...

Loops | Methods | Arrays(programming language java) in software (ATOM)

Write a toolkit that includes some common functions a user might want or need

  • An encryption/ decryption method. Both methods should take in a String (the String that needs to be changed), and an encryption value. The methods need to change the String by the value
  • Write a method that takes an integer array as an argument. The method should return the sum of all of the elements
  • Write a method that checks if an array contains a specific number

All user input should be in the main method. Arrays can be randomly generated, but Strings, values, and search values should be collected from the user
** Array length can be hard-coded or user input

** Array can be hard-coded [ 1, 4, 6, 87, 43, 56 ], use (int)Math.random(0, 100), or user input

Checklist

  • Encryption method (3)

Decryption method (3)

    • String and value are hard-coded (-1 in each method)
  • sum method (2)
    • Loops aren't generic (-1)
  • arrayContains method (2)
    • search value is hard-coded (-1)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;
import java.lang.Math;
public class Main
{
public static String encrypt(String input)
{
String output="";
for(int i=0;i<input.length();i++)
{
char ch = input.charAt(i);
ch=(char)(((int)ch+3)%128);
output=output+ch;
}
return output;
}
public static String decrypt(String input)
{
String output="";
for(int i=0;i<input.length();i++)
{
char ch = input.charAt(i);
ch=(char)(((int)ch+125)%128);
output=output+ch;
}
return output;
}
public static int sum(int[] array)
{
int sum=0;
for(int i=0;i<array.length;i++)
{
sum=sum+array[i];
}
return sum;
}
public static boolean isExists(int[] array,int number)
{
for(int i=0;i<array.length;i++)
{
if(array[i]==number)
{
return true;
}
}
return false;
}
   public static void main(String[] args)
   {
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter the size of array: ");
       int size = sc.nextInt();
       int[] array = new int[size];
       for(int i=0;i<size;i++)
       {
       array[i]=(int)(Math.random()*100);
       }
       System.out.print("Array: ");
       for(int i=0;i<size;i++)
       {
       System.out.print(array[i]+" ");
       }
       System.out.println();
       System.out.println("Sum = "+sum(array));
       System.out.print("Enter the number to search in array: ");
       int temp=sc.nextInt();
       if(isExists(array,temp))
       {
       System.out.println("Found");
       }
       else
       {
       System.out.println("Not found");
       }
       System.out.print("Enter the string to encrypt: ");
       sc.nextLine();
       String input=sc.nextLine();
       System.out.println("Encrypted: "+encrypt(input));
       System.out.println("Decrypted: "+decrypt(encrypt(input)));
   }
}

input Enter the size of array: 10 Array: 24 23 44 31 77 32 34 20 72 97 Sum = 454 Enter the number to search in array: 34 Foun

Add a comment
Know the answer?
Add Answer to:
Loops | Methods | Arrays(programming language java) in software (ATOM) Write a toolkit that includes some...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write...

    Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write a method (getData) that would ask user to enter a set of data – for example, five student names and corresponding scores. This program should also have the following methods:     getSum. This method should accept a studentScore array as its argument and return the sum of the values in the array.     getAverage. This method should accept a studentScore array as its argument...

  • In this lab, you complete a partially written Java program that includes methods that require multiple...

    In this lab, you complete a partially written Java program that includes methods that require multiple parameters (arguments). The program prompts the user for two numeric values. Both values should be passed to methods named calculateSum(), calculateDifference(), and calculateProduct(). The methods compute the sum of the two values, the difference between the two values, and the product of the two values. Each method should perform the appropriate computation and display the results. The source code file provided for this lab...

  • In this homework, create two arrays – studentName and studentScore (String and Int types). Write a...

    In this homework, create two arrays – studentName and studentScore (String and Int types). Write a method (getData) that would ask user to enter a set of data – for example, five student names and corresponding scores. This program should also have the following methods:     getSum. This method should accept a studentScore array as its argument and return the sum of the values in the array.     getAverage. This method should accept a studentScore array as its argument and...

  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • Playing With Arrays The following problems are to give you practice with programming with arrays. Write...

    Playing With Arrays The following problems are to give you practice with programming with arrays. Write a program to: 1.Ask the user for numbers and place them in an array sequencially. 2.Next, print out the values in the array in the order they are stored. 3.Search the array for the postion containing the smallest value. 4.Print out the position where the smallest value was found. 5.Swap the smallest value with the value in the first postition of the array. 6.Print...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • c++ Gebremed、e Diagram TX ent/d/1cukolouus-Gqbal8MgX-znWzblaCw Xbct4azy5f6Mi/edit Search Divide and Conquer. Y ) (132) Zayn x |...

    c++ Gebremed、e Diagram TX ent/d/1cukolouus-Gqbal8MgX-znWzblaCw Xbct4azy5f6Mi/edit Search Divide and Conquer. Y ) (132) Zayn x | Shared wit x Task 3: Task 2 (Repurpose Task 2 Assignment 3): Write a program that uses an array to find the Average of a set float values entered by the user You will have the main function control the operation of the program, but all values will be stored in the class. You will need to use get and set methods in your...

  • Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This...

    Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This method should accept a two-dimensional array as its argument and return the total of all the values in the array. Write overloaded versions of this method that work with int , double , and long arrays. (A) getAverage . This method should accept a two-dimensional array as its argument and return the average of all the values in the array. Write overloaded versions of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT