Assignment+1

discuss the assignment... see discussion posts above right


 * Task 1**

Enter a group? (Yes=1/No=0): 0 Total takings: $66

This 'sample run' (above) from the subject outline implies
 * 1) that '0' means stop, and
 * 2) that total takings is the sum of all inputs ($22 + $44)

Marks.java is in resources on Interact and below:
 * Task 2**

import java.util.Random;

/**
 * A class that provides a random array of marks,
 * approximately normally distributed.
 * @author Ken Lodge

public class Marks { private static final int NMARKS = 125; private static final double mean = 65.0; private static final double std = 15.0;

/** public static int[] getMarks { Random rand = new Random(1001L); int mark; int[] theMarks = new int[NMARKS]; int n = 0; while (n < NMARKS) { mark = (int) Math.round(std*rand.nextGaussian + mean); if (mark >= 0 && mark <= 100) theMarks[n++] = mark; } return theMarks; }
 * Returns an array of NMARKS integer marks approximately normally distributed,
 * with specified mean (mean) and standard deviation (std),
 * and with values outside 0..100 removed.
 * @return the array of marks.

/** public static void main(String[] args) { int[] testMarks = getMarks; for (int n = 0; n < testMarks.length; n++) { System.out.print(testMarks[n] + " "); if (n % 10 == 9) System.out.println; } }
 * Test code
 * @param args not used

}

//Exercise 5.19// is below:
 * Task 3**

public class Exercise5_19 { /** Main method */ public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); System.out.print( "Enter the first edge length (double): "); double edge1 = input.nextDouble;

System.out.print( "Enter the second edge length (double): "); double edge2 = input.nextDouble;

System.out.print( "Enter the third edge length (double): "); double edge3 = input.nextDouble;

if (MyTriangle.isValid(edge1, edge2, edge3)) { System.out.println("The are of the triangle is " + MyTriangle.area(edge1, edge2, edge3)); } else System.out.println("Input is invalid"); } }

class MyTriangle { public static boolean isValid( double side1, double side2, double side3) { return (side1 + side2 > side3) && (side1 + side3 > side2) && (side2 + side3 > side1); }

public static double area(double side1, double side2, double side3) { double s = (side1 + side2 + side3) / 2; return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3)); } }