Starting from:
$30

$24

CS Programming Lab 1 Solution

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 10 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 some details about lab grades Welcome to CS101 Fall 2021 Lab 01

There are 10 lab sessions in this course.

Labs contribute
to 25.0% of your total grade.
This lab:
2.5
points
All labs:
25.0
points

Please come prepared...

Good 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:

32.2 − 1.7 ÷ 2.2

73.5 × 16.4 − 36
(1. 2 + 0. 8)−1/3

(1.5 − 7.3) × (4.3 + 2.4)
5



34+2





and outputs the results as below:

Result of expression 1
is: -0.808730641463529

Result of expression 2
is: 7.218181818181816






Result of expression 3 is: 0.7937005259840998


3. Calculate Areas in the World

Finally, create a third file named Lab01_Q3 under the lab1 directory. Based on the information below,

    • The total area of the world is 510072000 km2.

    • 70.8% of this area is covered by water and the rest is dry land.

    • The total area of Turkey is 0.1536% of the world.

    • 1.3% percent of Turkey is water.

write a Java program in this file that uses the information above to answer the following questions:

    • How much of the area of the world is dry land and how much is water?

    • How much of the area in Turkey is dry land and how much is water?

    • What percent of the whole dry land of earth is in Turkey?

    • What percent of all water is in Turkey?

The output should look the same (except for perhaps some minor difference due to rounding) as the following sample run:


Earth has 148941024 km2 dry land and 361130976 km2 water.

Turkey has 773284 km2 dry land and 10185 km2 water.
Turkey has 0.519188051238321 percent of the Earth's dry land.
Turkey has 0.0028203063921052288 percent of the Earth's water.

Assume the area of the earth and the area of Turkey are constant values and declare them accordingly. However, the percentage of dry land may change over time so they should be declared using variables for any future changes. Notice that integers cannot hold very large numbers; so use long variables to hold the areas’ values. Finally, be careful of typecasting as we are not interested in the precision of the land area and long integers cannot hold fractions.

More products