Homework A

Due: Oct 27 prior to 11:59:59 PM

In this homework you will

Setup

Start by replicating much of Lab 1 with the following exceptions

The Program

Your program should get two random floating point numbers between 0 and 1.0 and store them into variables. Then print the value of each of those variables and print the sum of the two variables.

Here is a complete program for printing a random number between 0 and 1.0.
public class GTrand {
    public static void main(String[] args) {
        System.out.println(Math.random());
    }
}
Recall that the name of the class and the name of the file in which the class is stored must match; so for the code above, the file name must be "GTrand.java".

Ideally the output of you program would be something like
    0.44 + 0.25 = 0.69
only with a lot more numbers after the decimal points. An output like
    0.44
    0.25
    0.69
is OK, but will loose 1 point (out of a possible 100).

Valid Triangle

Next, create a new file in VS Code named ValidTriangle.java and copy/paste this code into it:
public class ValidTriangle {
   public static void main(String[] args) {
       int s1 = Integer.parseInt(args[0]);
       int s2 = Integer.parseInt(args[1]);
       int s3 = Integer.parseInt(args[2]);
       System.out.println(s1 + " " + s2 + " " + s3);
   }  
}
The above code will try to read three integers for the command line and print them. To run this program:
    javac ValidTriangle.java
    java ValidTriangle 10 11 12
which will produce the output
    10 11 12

Modify the program so that it displays "true" or "false" depending on whether the three numbers represent valid lengths of the sides of a triangle. The java if -- else statement is exactly identical to the one used in processing.

For three numbers to represent the valid lengths of the sides of a triangle, each number must be less than the sum of the other two.

Here are some cases

java ValidTriangle 7 10 8
true
 
java ValidTriangle 40 12 15
false
Finally, modify your ValidTriangle program so that it also displays "false" if any of the three values are 0 or negative. (Realistically the program would probably do so anyway, but add and explicit check for negative numbers.)

Submitting

Create a readme

Use VSC to create another file in your HW1 directory. This file should be named "Readme". The contents of this file should follow this sample.

You should have 5 files in your HW1 directory: GTAdder.java, GTAdder.class ValidTriangle.java, ValidTriangle.class and Readme. ("GTAdder" could be named something more meaningful for you.)

Submit

Open a terminal and execute the following Unix commands (assuming you put HW1 directory into a CS113 directory in your home directory).
    xena@loin:~$ cd
    xena@loin:~$ cd CS113
    xena@loin:~/CS113$ /home/gtowell/bin/submit -c 113 -d HW1 -p 1
In response to the final command you should see messages like:

CS Submission System Fall 2023
Submitting Project 1 for CMSC113 with gtowell

Creating archive for submission...
HW1/
HW1/GTAdder.class
HW1/GTAdder.java
HW1/Readme

Submitting archive...
Submission complete! Submission timestamp is 2023-08-08-15-30-28-EDT.

Looking at this output, you should see every file in the directory you want to submit listed, with the final line "submission complete".

Note that for future assignments you will use this same submission technique; so do try to get this to work. If you cannot get it to work, you may -- on this assignment, send me email containing the full text of your program and Readme. If you send email, you must also make an appointment to see me so I can help you to use "submit" on future assignments.