157 Lab
157 Lab

More Lab Basics


For this lab you'll ...
  1. Using only various variable declarations and mathematical and logical expressions, complete the following program that takes two integers as command line arguments. The program should print true if their sum is even and positive. Otherwise, print false.
     
    public class EvenSumClient{
    
      public static void main(String[]args){
    
        int a0 = Integer.parseInt(args[0]);
        int a1 = Integer.parseInt(args[1]);
    
        boolean result=false;
    
        // ?????
    
    
        System.out.printf("\n\n\tSum of %d and %d both even and positive:  %s"
                          , a0,a1, result); 
     
        System.out.printf("\n\n");
      }
    
    }
            
  2. Using only various variable declarations and mathematical and logical expressions, write a program that takes three integers as command line arguments. The program should print false if any of the three are not positive or if any one of them is greater than the sum of the other two. Otherwise, print true.

    fyi, this computation tests whether the three numbers could be valid lengths fo the sides of some triangle.

  3. Write a program that takes two integer command line arguments a and b and prints a five random integers all between a and b inclusive.
  4. Write a program generates five random numbers between 0 and 1, their average, and their minimum and their maximum. Use Math.random()   Math.min()   Math.max() . You may need to go back and read the documentation for one or more of these Math functions.
  5. Write a program that takes a double command line argument,t, and prints the value of

    sin(2t) + sin(3t)

  6. Using only various variable declarations and mathematical and logical expressions, write a program that takes two integer command line arguments m and d and prints true if day d of month m is between 8/20 and 11/20. Program should otherwise print false
  7. Write a program that calculates and prints the amount of money you would have after t years if you invested P dollars at an annual interest rate r where the desired value is given by formula Pert. t,P,r should all be obtained from command line arguments.
  8. If you don't already know, look up the definition of a "Great Circle".

    Now, write a program that takes four double command line arguments -- lat1,lng1,   lat2,lng2-- (the latitude and longitude, in degrees) of two points on the earth's surface and prints the great circle distance between them. The great circle distance, measured in nautical miles, is calculated by the following equation:

                                       60 arccos(
                                                 sin(lat1)sin(lat2) 
                                                 + 
                                                 cos(lng1)cos(lng2)cos(lng1-lng2)
                                                )