Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


CS 101: Intro to Computer Science

 

Homework 1

Programing Question (5 marks)

You are a computer scientist working at SpaceX. The engineers want to calculate the position of the rocket after its launch.We have been given with an initial position and speed, we need to calculate  the  final  position  of the rocket after given time t seconds.  For the given example

consider that the initial position is 2 meters and a speed of 5 meter/second.

We use the given formula to calculate the final position of the Rocket :

 

finalPosition = initialPosition  + Speed*t

For example, the Final Position after 3 seconds would be :

Final Position = 2 + 5 * 3 = 2 + 15 = 17

Ignore the identifiers like int, String for now.

public class SpaceX{

public static void main (String [] args){

int initialPosition = 2;

int time = // Assign a numeric value to the variable here like the

statement above, ignore the identifier ‘int’ for now.

int Speed = // Assign a numeric value to the variable here like the

statement above, ignore the identifier ‘int’ for now.

// You can use variables in mathematical expression such as for

variables FinalPosition = InitialPosition  + Speed*t

int finalPosition = // Complete the expression

// Write a print statement here such that it outputs your name in a

separate line.

System.out.print ("Final Position : "+ finalPosition + "

m");

}

}

Write the steps for compilation and execution as well.

Now, the engineers are interested in finding the final velocity after the t seconds with speed and initial position of rest as before.

Test your output when

● t = 2 seconds.

● t = 5 seconds.

● t = 10 seconds.

● t = 0 seconds.

Output your name in the console such that it appears on a separate line and before the output System.out.print ("Final Position : "+ finalPosition + " m");

Submit your code file named SpaceX.java as part of your assignment.

Sample Output :

 


Theory Questions

Java (2 marks)

Suppose you have started your own company. You get a request from a Client which requests you to create an Application. However, the Client wants to use the same Application on various platforms. Is it possible to build the same Application which runs across different platforms ? Can any features of Java come in handy in such a situation? If so, name the feature/s and explain how it is useful.

Shell and OS (3 marks)

1. What is a Shell? Name some softwares that can be used as a shell.

2. What is a filesystem? What are the default permissions when a file is created? For the following parts mention the commands to perform the required operations.

3. Write a command line statement to make a new folder with name cs-101 and traverse into the directory

4. Once inside, create a new file cs101.text with content “Hello CS 101”

5. Output the contents of the file on the console.

In case of any questions or clarifications, please create a post on the BrightSpace Forum or reach out to [email protected].


Submission Details :

1.   Create the File SpaceX.java as given in the Part - 1 (Programming Question). Complete the Expressions and show computation for t = 2.

2.   For other parts pdf file in the format netID_CS101_HW1_pdf.pdf (For Example : dd3053_CS101_HW1_pdf.pdf)

3.   This pdf should contain the following Sections :

Part - 1 (Programming Question) : The answer to the outputs of various final Positions for different t time.

Part - 2 (Java) : Write the Answer.

Part -  3(Shell and OS) : Write the answers to the different parts. For commands, just mention the commands.

4.   Create a zip file containing the SpaceX.java and netID_CS101_HW1_pdf.pdf and name it as netID_CS101_HW1.zip(For example : dd3053_CS101_HW1.zip)

5.   Submit the common Zip File created in Step 4 on GradeScope.

6.   Submission Deadline :Feb 8, 11:59 pm EST