$34.99
For all labs, your solutions must conform to the CS101 style guidelines!
All data and results should be stored in variables (or constants where appropriate) with meaningful names.
The objective of this lab is setting up & using a Java IDE, and writing some basic Java programs & debugging. Remember that analyzing your problems and designing them on a piece of paper before starting implementation/coding is always a best practice.
0. Setup Workspace
In VSC, you organize your programs into workspaces. A Visual Studio Code workspace is basically a collection of one or more folders that are opened in a VS Code window (instance). For CS101 labs, we would like you to create a single workspace where you collect all lab solutions. First, create a folder named labs in your chosen folder on your hard disk. Then start VSC and open this folder (File > Open Folder...). Now in VSC, under labs, create a new folder named lab1. Then, save the current workspace as labs_ws under the folder labs (File > Save Workspace As...). Now you have a workspace, within which you can create folders (one for each lab) and classes for your Java programs under each folder as needed.
In this lab, you are to have three Java classes/files (under labs/lab1 folder) as described below.
1. Fix Compile Errors
First, download the provided Lab01_Q1.java from Moodle under the lab1 directory. When you try to compile this program, it will give errors and will fail.
Your task here is to fix the compile errors in this program to get an output exactly as below:
Hi everyone, below are details about lab grades
There will be 9 lab sessions in this course.
Labs contribute to 25.0% of your total grade.
This lab: 2.7777777777777777 points All labs: 25.0 points You should come prepared...
Best of luck!
2. Calculate Simple Expressions
Now create a new/empty file of your own under the lab1 folder named Lab01_Q2.java with a class with the same name that calculates these expressions:
2 and outputs the results as below:(1.5 32− 7.2.3 −) ×17 ( 4÷.3 22 + 24) 73.5 × 2165 +.4 34− 3 × 81 (2. 4 − 0. 4)−2/6
Result of expression 1 is: -0.19617399780675038
Result of expression 2 is: 7.218181818181816 Result of expression 3 is: 0.7937005259840998
3. Calculate Mass and Atom Count in Human Body
Finally, create a third file named Lab01_Q3 under the lab1 directory. Based on the information below,
- 98.6% of the mass of the human body is made up of six elements: oxygen (65%), carbon (18.5%), hydrogen (10%), nitrogen (3.2%), calcium (1.5%), and phosphorus.
- A 70kg human body contains approximately 7×1027 atoms. The number of atoms of each element however is distributed differently. For instance, only 24% of the number of atoms in the human body are oxygens, whereas 62% of the number of atoms are hydrogens.
Write a Java program in this file that uses the information above to answer the following questions:
- What percentage of the mass of the human body is phosphorus?
- What percentage of the mass of the human body are elements other than the ones specified?
- What percentage of the number of atoms of the human body are elements other than the ones specified?
- For a 70kg person, what are the mass (as fractional numbers) and the number of atoms of the elements with the highest two ratios?
Phosphorus makes up 0.3999999999999915 percent of the mass in the human body.
Elements other than oxygen, carbon, hydrogen, nitrogen, calcium and phosphorus make up 1.4000000000000057 percent of the mass with an atom count of 9.800000000000001E26.
For a person of 70.0 kg the mass of the elements are:
Oxygen: 45.5kg Carbon: 12.95kg
whereas the number of atoms of some elements in this person are:
Hydrogen: 4.34E27
Oxygen: 1.68E27
Assume the distribution of the percentages of the mass and the number of atoms in the human body are constant values and are declared accordingly. The weight of a particular human, however, should be a variable.
Notice that integers cannot hold very large numbers; long variables might not be sufficient to hold certain values in this program either. So you might have to use doubles.