Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Homework Assignment #7 Homework Assignment #7 Start Assignment Due Thursday by 11:59pm Points 10 Submitting a file upload Available Apr 21 at 12am - Jun 7 at 11:59pm about 2 months File Types java PLATFORM INDEPENDENCE Please see Syllabus for more information

Homework Assignment #7 Homework Assignment #7 Start Assignment Due Thursday by 11:59pm Points 10 Submitting a file upload Available Apr 21 at 12am - Jun 7 at 11:59pm about 2 months File Types java PLATFORM INDEPENDENCE Please see Syllabus for more information

Sociology

Homework Assignment #7 Homework Assignment #7 Start Assignment Due Thursday by 11:59pm Points 10 Submitting a file upload Available Apr 21 at 12am - Jun 7 at 11:59pm about 2 months File Types java PLATFORM INDEPENDENCE Please see Syllabus for more information. Your solution has to be platform-independent; it must run on any platforms including any online IDEs: You solution should be free of any use of packages. Example, absolutely no /* Java Program Example - Java Import Packages * package YOUR_CUSTOM_PACKAGE HERE; Your solution, regardless of how many classes it has, should be in one .java file. Your solution has to run on any online IDEs. If your solution fails the platform-independence criteria, you will have to resubmit work subject to the late penalty. The Late Work policy applies for all late submissions. Your solution should be reusable, meaning it will be invoked and validated against a series of input sequentially to produce consistent outcomes like so: Solution sol = new Solution(); sol.your_method1(test_input_1...); sol.your_method2(test_input_2 ...); PROBLEM 1 ( 10 points ) You can create an array of integers, [1,2,3], as follows: List ints = new ArrayList(Arrays.asList(1, 2, 3)); These integers are in an ArrayList which is a Java Collection that implements Iterator, which can be invoked by: ints.iterator(); The above iterator is initialized to the beginning of the list. For this problem, you will write a custom Iterator interface called MyIterator with the THREE (3) following methods: (): returns the next element in the iteration. hasNext() : returns true if the iteration has more elements, next https://online.smc.edu/courses/38679/assignments/739870 false otherwise. 1/4 4/23/2021 lookAhead() Homework Assignment #7 : returns the element that will be returned by the next invocation of next() . Note this method is completely custom. You will need to implement logic to correctly return the right element. This method returns the next element in the iteration WITHOUT advancing the iterator. lookAhead() You will start with the following code template. STARTER CODE import java.util.*; public class Solution1 { public static void main(String[] args) { // Your solution will be tested as such, with random input lists such as the following List ints = new ArrayList(Arrays.asList(1, 2, 3)); MyIterator iter = new MyIterator(ints.iterator()); System.out.println(iter.next()); // 1 System.out.println(iter.lookAhead()); // 2 System.out.println(iter.next()); // 2 System.out.println(iter.next()); // 3 System.out.println(iter.hasNext()); // false } } class MyIterator implements Iterator { // ============================================== // ANY GLOBAL VARIABLE DECLARATIONS HERE // ============================================== public MyIterator(Iterator iterator) { // ============================================== // YOUR INITIALIZATIONS HERE // ============================================== } /** * PURPOSE: * PARAMETERS: * RETURN VALUES: */ public Integer lookAhead() { // ============================================== // YOUR CODE HERE // ============================================== } /** * PURPOSE: * PARAMETERS: * RETURN VALUES: */ @Override public Integer next() { // ============================================== // YOUR CODE HERE // ============================================== } /** * PURPOSE: * PARAMETERS: * RETURN VALUES: */ @Override public boolean hasNext() { // ============================================== // YOUR CODE HERE https://online.smc.edu/courses/38679/assignments/739870 2/4 4/23/2021 } } Homework Assignment #7 // ============================================== EXAMPLES // TEST CASE #1 List ints = new ArrayList(Arrays.asList(1, 2, 3)); MyIterator iter = new MyIterator(ints.iterator()); System.out.println(iter.next()); // 1 System.out.println(iter.lookAhead()); // 2 System.out.println(iter.next()); // 2 System.out.println(iter.next()); // 3 System.out.println(iter.hasNext()); // false // TEST CASE #2 List ints = new ArrayList(Arrays.asList(100)); MyIterator iter = new MyIterator(ints.iterator()); System.out.println(iter.next()); // 100 System.out.println(iter.lookAhead()); // null System.out.println(iter.next()); // null System.out.println(iter.hasNext()); // false CONSTRAINTS / ASSUMPTIONS Input ArrayList cannot be empty or null; it has at least one elements. Invoking next() when the iterator is already at the end of list returns null . Invoking hasNext() when the iterator is already at the end of list returns false . Your solution will be validated against 9-10 test cases; -1 for each failed test. HINTS Refer to the Iterator interface the Oracle API for Java 8. Refer to the List interface (https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html) in (https://docs.oracle.com/javase/8/docs/api/java/util/List.html) in the Oracle API for Java 8. Refer to the ArrayList class the Oracle API for Java 8. (https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html) in List is an interface while ArrayList is a class, which implements the List interface. ArrayList is a subtype of List interface. In Java or any object-oriented programming language (OOP), supertype of a variable can store an object of subtype. This is a type of polymorphism in OOP as described in this article (https://www.java67.com/2016/01/difference-between-list-and-arraylist-variable-in-java.html) . Lastly, Array is a fixed length data structure whereas ArrayList is a variable length Collection class. We cannot change length of array once created in Java but ArrayList can be changed. We cannot store primitives in ArrayList, it can only store objects. But array can contain both primitives and objects in Java. https://online.smc.edu/courses/38679/assignments/739870 3/4 4/23/2021 Homework Assignment #7 90/10 (1 Problem) Criteria (1) LOGIC - correct output (-1 pt for each failed test case) Ratings 9 pts Correct 4 pts Effort Pts 0 pts Incorrect 9 pts Showing effort though logically incorrect (1) LOGIC - incorrect function signature Code does not meet platform independency test; code cannot compile. You may resubmit for partial credit. (1) STYLING/DOCUMENTATION 0 pts Incorrect 1 pts Included 0 pts Incorrect 0 pts 0 pts Not included 1 pts Total Points: 10 https://online.smc.edu/courses/38679/assignments/739870 4/4

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions