Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

GMU Spring 2023 – CS 211 – Project 1 Description The purpose of this assignment is to get practice with strings, arrays, loops and dynamic memory allocation. Instructions  ...

1 answer below »
GMU Spring 2023 – CS 211 – Project 1
Description
The purpose of this assignment is to get practice with strings, a
ays, loops and dynamic
memory allocation.
Instructions

 Documentation : Comments are not required in this assignment but it’s a good practice to
add comments to any piece of code that is not obvious what it does.
 Imports : You may not import any classes or packages.
 You are not allowed to use any language construct that hasn’t been covered in class yet.
1
Grading

• If your code doesn’t pass all the compliance checks in Gradescope, it means that
something fundamental is wrong and we won’t be able to grade it unless you +x it. You
will get zero points if you don’t +x and reupload your code.
Task
You will implement the following methods in Java. Every method is self-contained; there are no
dependencies among the methods. You’re free to create helper methods if you want though.
Make sure you do not modify the method signatures that are provided, otherwise your code will
not pass the compliance checks and we won’t be able to grade it.
2
public static int stringValue(String word)
It returns the value of a string which is the sum of the values of its characters. The value of each
character is the ASCII code of the character (e.g. A has a value of 65, B has a value of 66, a has a
value of 97, etc.) with a few exceptions:
• Double-letters (e.g. ee, mm, ll, tt, etc.) are valued once, not twice.
• The space character has a value of zero
• The value of each number-character is multiplied by the largest value of the non-number-
characters in the string.
To simplify things a bit, assume that the word will not include, and your program will not be
tested with, any characters that have an ASCII code lower than 40 or higher than 123.
Examples:
word return solution
Mason XXXXXXXXXX110
Ma son XXXXXXXXXX+110
mass XXXXXXXXXX
50 Cent XXXXXXXXXX*116+48* XXXXXXXXXX
public static double expValue(int x, double precision)
The calculation of the ex function appears a lot in applications and it’s considered quite an
expensive computation. One way to calculate it is with the following formula:
e
x
=∑k=0
∞ x
k
k !
=1+x+
x
2
2
+
x
3
6
+
x
4
24
+ ...
As you can tell, this series can go for ever. After some point though, the precision of the result
doesn’t improve much. Therefore, we can stop adding terms when the improvement is less than
the precision parameter. In other words, if adding a certain term changes the result by less
than the value of precision, then we do not add this term and we stop the series. The method
eturns the sum of the series.
3
https:
en.wikipedia.org/wiki/ASCII
public static int mi
orNum(int num)
The method accepts an integer and returns the mi
ored integer. In case of a negative number,
it retains the sign.
You may not use any classes from any package, not even the Math and String classes, to
implement the mi
orNum method
Examples:
num return
4 4
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
public static boolean raisedNum(long num)
There are some numbers whose value is the sum of x y+ yx where x and y are integers greater
than 1. Let's call these numbers raised numbers. Write a method that accepts a long and
eturns true if the number is raised, and false otherwise.
Examples:
input return solution
6 false
17 true 23 +32
593 true 92 +29
1125 false
4
public static int[][] smallestSuba
ay(int[][] a
ay, int sum)
It takes a rectangular a
ay and returns a square-size suba
ay of it whose values have a sum
that is equal or larger to sum. A suba
ay can’t be smaller than 2x2. If there are more than one
square-size suba
ays that satisfy the requirements, the method must return the square that
has the smallest size. If two or more equally-sized squares satisfy the requirements, it must
eturn the square whose values have the highest sum. Assume that the sum has such a value
that always wa
ants a solution (i.e. no need to check or wo
y about this).
Examples:
a
ay sum return
{{0,1,2},{-4,5,6},{7,8,3}} 5 {{5,6},{8,3}}
{{0,1,2},{-4,5,6},{7,8,3}} 23 {{0,1,2},{-4,5,6},{7,8,3}}
public static void replaceElement(int[][] a
ay, int elem, int[] newElem)
It takes a two-dimensional a
ay and modi+es it in-place (i.e. the method doesn’t return
anything). Every occu
ence of elem is replaced by the items contained in newElem. The
modi+cation must happen in-place, i.e. the memory address of the whole a
ay must remain the
same; but the memory addresses of its rows can change of course.
Examples:
a
ay before method invocation elem newElem a
ay after method invocation
{{1,2,3,4,5},{6,7,8}} 2 {0} {{1,0,3,4,5},{6,7,8}}
{{1,2,3,4,5},{5,4,3,2}} 5 {-5,5} {{1,2,3,4,-5,5},{-5,5,4,3,2}}
{{0,1,2,3,4,5},{5,4,3,4}} 4 {1,2,3} {{0,1,2,3,1,2,3,5},{5,1,2,3,3,1,2,3}}
5
public static int[][] removeDuplicates(int[][] a
ay)
It takes as input a two-dimensional a
ay and returns a new two-dimensional a
ay where every
sequence of duplicate numbers is replaced by a single occu
ence of the respective number.
Keep in mind that duplicate numbers can extend in more than one rows though.
Examples:
input a
ay returned a
ay
{{1,2,3,4,5},{6,7,8,9}} {{1,2,3,4,5},{6,7,8,9}}
{{1,2,2,2,3,4,5,5},{6,7,8,8,8,9}} {{1,2,3,4,5},{6,7,8,9}}
{{1,2,2,2,3,4,5,5},{5,5,5,5},{5,5,9}} {{1,2,3,4,5},{9}}
public static int[] vortex(int[][] a
ay)
It takes as input a two-dimensional rectangular a
ay, traverses its contents in a clockwise spiral
order starting from index (0,0), and returns the result as a single-dimensional a
ay.
Examples:
input a
ay returned a
ay
{{1,2,3},{4,5,6},{7,8,9}} {1,2,3,6,9,8,7,4,5}
{{1,2},{3,4},{5,6},{7,8},{9,10}} {1,2,4,6,8,10,9,7,5,3}
{{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},
{16,17,18,19,20}}
{1,2,3,4,5,10,15,20,19,18,17,16,11,6,7,8,9,14,13,12}
6
    Changelog
    Description
    Instructions
    Submission
    Grading
    Testing
    Task
Answered 11 days After Feb 06, 2023

Solution

Vikas answered on Feb 11 2023
36 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here