Homework Assignment #1 CS5004 solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Problem 1 [6pts]. Determine the answer to the following expressions. You must provide
a short explanation (a sentence of two) for each one.
• 2 % 3
• 0 % 3
• 3 % 3
• -2 % 3
• 2 % -3
• -2 % -3
Submission format: A text file problem1.txt.
Problem 2 [5pts]. We all know about bits and bytes. In particular we know that 1 byte
equals 2
3 = 8 bits. Now, you might have noticed that a hard disk drive which is advertised as
having a capacity equal to 500 Gigabytes, shows up in your operating system with a smaller
number, approximately 465. Why is that? It is because, in marketing, the SI1 units are
used where 1Kilo = 103 = 1000. On the other hand, in computer science we use the IEC2
standard where 1Kilo = 210 = 1024. To avoid confusion, when working with powers of 2, we
are supposed to write KiB instead of KB (i.e. kibi instead of kilo) and so on.3 For example
1MB = 1000KB = 1000 × 1000B = 106B
1MiB = 1024KiB = 1024 × 1024B = 220B
In this problem, you write a simple program that coverts giga to gibi. For example, given
500GB as input you must calculate its equivalence in GiB. Below is a skeleton for the code
1Systèm Internationale
2
International Electrotechnical Commission
3Read https://en.wikipedia.org/wiki/biary_prefix
1
public class Converter {
public static void main(String[] args) {
long giga = 500;
long gibi = 0;
// your code for computing gibi from giga
System.out.println(giga + “GB = ” + gibi + “GiB”);
}
}
Submission format: A java source file Converter.java.
Problem 3 [4pts]. The following program will compile and run, but it uses a poor programming style. Modify the code so that it uses the coding conventions described in the
class and mentioned in the book.
public class mess {
public static void main(String[] args)
{
double TIME; double PACE;
System.out.println(“This program calculates pace”);
TIME = 35.5; /* 35 minutes and 30 seconds */
PACE = TIME / distance;
System.out.println(“Pace is ” + PACE + ” miles per hour.”);
double distance = 6.21;
}
}
Refer to §1.4 (Program Style) in your book or consult the slides. Submission format: A
Java source file with the correct name and extension.
2