[SOLVED] CS2040S-Data Structures And Algorithms: Problem Set 1

25.99 $

Category:

Description

5/5 - (1 vote)

Problem 1.           (Getting up and running)

In CS2040S, we will be writing programs in Java. We will be using IntelliJ as our basic development environment. IntelliJ is available as an open-source (Apache 2.0) Community version that has all the functionality needed for CS2040S, and runs on Windows, Macs, and Linux. It contains useful editing, debugging, and profiling tools. You can download it at: https://www.jetbrains.com/idea/download/

Problem 1.a. Start IntelliJ and create a new Java project called ps1 for this problem. Choose Java version 11.0.9 for Project SDK. If you do not have the SDK, download it here. Inside the src folder, create a new Java class called Main.java (the name is case sensitive!). Within this class, create the following method:

static int MysteryFunction(int argA, int argB) { int c = 1; int d = argA; int e = argB; while (e > 0) { if (2*(e/2) !=e) { c = c*d;

}

d = d*d; e = e/2;

} return c;

}

Also, create the following main function:

public static void main(String args[]) { int output = MysteryFunction(5, 5);

System.out.printf(“The answer is: ” + output + “.”);

}

Run your program. What is the answer output in your solution?

Problem 1.b. (Optional.) What is MysteryFunction calculating? If you try a few examples, you might be able to guess.

Problem 1.c. Create a “Hello CS2040S!” program that is designed to introduce yourself to your tutor and name it HelloWorld.java. It can be as simple or complicated as you like. It should output (in some form):

  • your name (as you prefer to be called),
  • your favorite algorithm or your favorite joke,
  • a few sentences of additional information on your background and who you are (but nothing private that you would want kept secret from the rest of the class),
  • the answer(s) to the previous parts.

This HelloWorld.java file is the only part of this problem to submit.