HW#1 --- last modified January 16 2019 00:35:13..A solution set is posted here. Due date: Sept. 17. by start of class ========= Files to be submitted: cs151sec3hw1.java (send via e-mail) ====================== Also turn in on paper at start of class problem 1.1 out of Jia. Purpose: (1) To check that our Java skills are still with us. ======== (2) To gain some experience with OO-modeling. Specification: ============== Besides doing problem 1.1 out of Jia on this assignment you will write a Java application which takes its first command line argument's value (say x) and writes out the xth largest of the remaining command line arguments. For instance, if at the the command line I type: java cs151sec3hw1 4 8 37 3 2 5 your program should write: 3 since 3 is the fourth largest number among 8, 37, 3, 2, and 5. All input/output should be done using System.in / System.out. Your program should consist of two classes: cs151sec3hw3 (for this class we'll allow the driver class containing main to start with a lower case) and OrderedNums. OrderedNums has one constructor: OrderedNums(int i, String arr[]), one private method: sort(), and one public method: kLargest(int k). It also has a private field: int numbers[]. The constructor for OrderedNums works as follows: It begins at the ith element of arr[] and converts each element in turn to an int and stores this int in numbers. It then calls sort(). The sort() uses whatever sorting algorithm you know and want to code to sort numbers from its largest to smallest element. kLargest(int k) just returns numbers[k-1]. i.e., the largest element would be obtained by calling kLargest(1). cs151sec3hw1's main method simply creates an instance myNums of OrderedNums using 1 and args[] as the arguments to OrderedNums constructor. It then calls myNums.kLargest(args[0]); and writes out the result. For this homework you do not needed to be able to handle exceptional inputs and any exceptions should be thrown. Point Breakdown =============== Problem 1.1 (one point for each of a,b,c,d) 4pts cs151sec3hw1 works as described 1pt OrderedNums constructor works as described 1pt sort() does sort numbers 1pt kLargest returns the kth largest elt 1pt Total..................................8pts A solution set is posted here. |