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

[CSE 007] Lab 1: Variables, Casting & Arithmetic

Date Assigned: 27 January 2023                         Date Due: 2 Feb 2023 @ 11:59 pm

A note about this assignment: There is quite a bit of code provided for you in the following activities. You are expected to incorporate the code into complete Java programs. It is important that you take your time with this lab activity, and read each section carefully.

Submission: You will submit three (3) programs for this lab: HelloWorld.java, HelloClass.java, ConvertWeight.java

Part 0: Your IDE and Java

Objective: In this lab, you will make sure you have your IDE properly running. Recall     that no specific IDE is required, but you will need some software that allows you to create/write java files. I will expect you to know terminal commands, so I highly encourage you to use software that requires you to open a terminal window (e.g., Eclipse does *not* use a terminal window).

Documentation to download VSCode and the java compiler (JDK 11) can be found on CourseSite!

*Todd George, CSE System Admin, will be able to troubleshoot if/when issues arise

Ifyou run into technical difficulties after class, reach out to todd.george@lehigh.edu

Part 1: Hello, World

Objective: Your first program will be simple, but elegant: We will tell the computer to  say“hello”by translating human language to computer-readable commands. Your       program should use good programming practices (i.e., include a header and comments and use proper indentation).

1)  Open your IDE (or the terminal window) and create a new file called “HelloWorld.java”.

2)  The name of your java file must match the name of your class.

3)   Provide a header at the top of your file using block commenting that includes your name, the date, and the labelCSE007 Spring 2023: Lab 1”

a)  Block commenting is used to describe details of a program

b)  Syntax:

/* This is a block comment

* still in the comment!

* here too! */

4)  Next, include the main method.

5)  Finally, instruct your computer to say“Hello, World”, by using the println method to print this message to STDOUT.

6)  Your program should look like that in the image below (but make sure you include an appropriate header and comments!)

7)  Compile your program at the command line using javac HelloWorld.java

8)  Run your program at the command line using java HelloWorld

9)  Check that“Hello, World”is displayed on your screen, and verify your results with a partner.

**NOTE: Are you experiencing compiler errors? Do you even know what a compiler  error is?? Even if the answer is“no”right now, we will build an understanding and an appreciation for compiler errors. And, we’ll also learn more about runtime errors.   Errors can be frustrating, but take time to familiarize yourself with any you encounter and the messages your compiler prints to the terminal window. You will almost surely see them again. Throughout the semester, we will discuss how to use them to your      advantage to debug your programs.

Part 2: Introducing yourself to the class (HelloClass.java)

Objective: You will create a program consisting of multiple print statements in order to introduce yourself to the class (and graders!).

TODO:

1.  Begin by creating a program called HelloClass.java.

2.  Provide a header at the top of your file using block commenting that includes your name, the date, the label“CSE7 Lab 1”, and a brief description of the program.

3.  Next add the class and main method structures. Don’t forget that the class name must EXACTLY match the filename. Use the HelloWorld code as an example.

4.  Within the main method, add multiple print statements in order to display the following information:

a.  Name

b.  Year at Lehigh

c.   3 Fun Facts (on separate lines / using separate print statements)

d.  Something you are looking forward to this semester.

5.  Next, compile and run your code. If any compiler errors occur, read the error statements carefully. Many errors are descriptive, and all will give you a line   number to refer to. Use this information to revisit your code and“debug”your program. If an error confuses you, try asking someone else (or, researching it   online).

Part 3: Basic Expressions (ConvertWeight.java)

Objective: You will create a program using the code provided below that is intended to convert weight in pounds to kilograms.

TODO:

1.  Begin by creating a program called ConvertWeight.java

a.  Remember that your file name should match the class name (though the class name will not include the .java extension).

2.  Provide a header at the top of your file using block commenting that includes your name, the date, and the labelCSE007 Spring 2023: Lab 1”

a.  Include a description of the program as well as the IDE used to create it, too.

3.  Next, include the main method.

4.  Within the main method, define the following variables:

a.   final double kgPerPound = 0.45359237;

i.     This is the conversion factor to change pounds to kilograms. In other words, 1 pound is equal to .4535.. kg.

b.  double weightInPounds = 150.32;

i.     This is the weight (in pounds) that we want to convert to kilograms

c.   double weightInKilograms;

i.     This variable will hold the total weight converted to kilograms (calculated using the previous two variables).

5.  Next, write an expression to convert weightInPounds into kilograms and assign that value to weightInKilograms.

a.  See screenshot below for guidance.

6.  Finally, display the output in a meaningful way.

7.  Next, compile and run your code.

Expected output: 150.32 is equivalent to 68.1840050584 kg

Grading Rubrics:

1.  HelloWorld.java [25 pts]

a.  Good Programming Practices: x/10

i.     Header comment, indented/formatted code (+5 each)

b.  Code Compiles: x/5

c.   Output matches expected: x/10

2.  HelloClass.java [50 pts]

a.  Good Programming Practices: x/5

i.     Header comment, indented code

b.  Code Compiles: x/15

c.   Output matches expected: x/30

i.     +5 pts for each print statement

1.  Name

2.  Year at Lehigh

3.  3 Fun Facts (on separate lines)

4.  Something you are looking forward to this semester.

3.  ConvertWeight.java [25 pts]

a.  Good Programming Practices: x/10

i.     Header comment, indented/formatted code (+5 each)

b.  Code Compiles: x/5

c.   Output matches expected: x/10

i.     150.32 is equivalent to 68.1840050584 kg