Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To completed A4Exercises and A4LinkedList public class A4Exercises { /* * Purpose: add valToAdd to all elements in the given array * Parameters: int[] array

To completed A4Exercises and A4LinkedList

public class A4Exercises {

/* * Purpose: add valToAdd to all elements in the given array * Parameters: int[] array - the array to modify * int valToAdd - the value to modify items by * Returns: void - nothing */ public static void addToAll(int[] array, int valToAdd) { addToAllRecursive(array, valToAdd, array.length-1); } private static void addToAllRecursive(int[] array, int valToAdd, int i) {

} /* * Purpose: determines whether the given array contains toFind * Parameters: int[] array - the array to search * int toFind - the value to search for * Returns: boolean - true if found, false otherwise */ public static boolean arrayContains(int[] array, int toFind) { return arrayContainsRecursive(array, toFind, array.length-1); } private static boolean arrayContainsRecursive(int[] array, int toFind, int i) { return false; // so it compiles } /* * Purpose: gets the number of times there are two of the same element in a row * Parameters: int[] array - the array to search * Returns: int - the number of occurrences where two adjacent elements are the same */ public static int sameInARow(int[] array) { return sameInARowRecursive(array, -1, array.length-1); } private static int sameInARowRecursive(int[] array, int prev, int i) { return 0; // so it compiles } }

public class A4LinkedList implements A4List { // Completed for you, should not be changed private StudentNode head; private StudentNode tail; private int numElements;

// Completed for you, should not be changed public A4LinkedList() { head = null; tail = null; numElements = 0; } // Completed for you, should not be changed public int size(){ return numElements; } // Completed for you, should not be changed public boolean isEmpty() { return head == null; } // Completed for you, should not be changed public void insert(Student s) { StudentNode n = new StudentNode(s); if (head == null) { head = n; } else { tail.next = n; } tail = n; numElements++; } /* * Purpose: create a string representation of list * Parameters: none * Returns: String - the string representation * * Completed for you, should not be changed */ public String toString() { return "{" + toStringRecursive(head) + "}"; } public String toStringRecursive(StudentNode cur) { if (cur == null) { return ""; } else if (cur.next == null) { return cur.getData().toString() + toStringRecursive(cur.next); } else { return cur.getData().toString() + ", " + toStringRecursive(cur.next); } }

public boolean inProgram(String program) { return inProgramRecursive(head, program); } private boolean inProgramRecursive(StudentNode cur, String program) { return false; // so it compiles }

public Student getStudent(String sID) { return getStudentRecursive(head, sID); } private Student getStudentRecursive(StudentNode cur, String sID) { return null; // so it compiles } public double averageGPA() { if (size() == 0) { return 0.0; } else { return sumGPARecursive(head)/size(); } } private double sumGPARecursive(StudentNode cur) { return 0.0; // so it compiles } public double programAverage(String program) { // call a recursive helper method! return 0.0; } public Student highestGPA() { // call a recursive helper method! return null; }

}

public interface A4List { /***************************************************************** * The first 3 methods are completed for you in A4LinkedList.java * *****************************************************************/ /* * Purpose: get the number of elements in the list * Parameters: none * Returns: int - the number of elements in the list */ public int size(); /* * Purpose: determines whether the list is empty * Parameters: none * Returns: boolean - true if empty, false otherwise */ public boolean isEmpty(); /* * Purpose: inserts a student at the back of the list * Parameters: Student s - the student to insert * Returns: void - nothing */ public void insert(Student s); /**************************************************** * You will need to complete the following 5 methods * ****************************************************/ /* * Purpose: determines whether the list contains * a student in the given program * Parameters: String - the program to search for * Returns: true if a student in the given program is found, false otherwise * Precondition: program is not null */ public boolean inProgram(String program); /* * Purpose: gets a student with the given sID, if the * list contains a student with the given sID * Parameters: String - the sID to search for * Returns: Student - the student if found, null otherwise * Precondition: sID is not null */ public Student getStudent(String sID); /* * Purpose: get the average GPA of all students in the list * Parameters: none * Returns: double - the average GPA of all students */ public double averageGPA(); /* * Purpose: gets the average GPA of all students in the given program * Parameters: String - the program to search for * Returns: double - the average gpa of all students in the program * Precondition: program is not null */ public double programAverage(String program); /* * Purpose: get the student with the highest GPA in the list * Parameters: none * Returns: Student - the student with the highest GPA */ public Student highestGPA();

}

image text in transcribed

image text in transcribedimage text in transcribed

* student.java * A Student class * public class Student ( private String SID; private double ypa; private string program; public Student (String SID, double gpa, string program) { this.SID = SID; this.gpa = gpa; this.program = program; } SID /* + Purpose: set's this student's SID to SID parameter value * Parameters: String * Returns: nothing */ public void setSID (String SID) { this.SID = SID; } * Purpose: returns this Student's SID * Parameters: none * Returns: String - the SID */ public String getSID() { return this. SID; } /* * Purpose: set's this student's gpa * Parameters: double - gpa + Returns: nothing */ public void setGPA (double gpa) { this.gpa = gpa; } * Purpose: returns this Student's grade * Parameters: none * Returns: double - the gpa public double getGPA() { return this.gpa; /* * Purpose: set's this Student's program * Parameters: String program * Returns: nothing */ public void set Program(string program) { this.program = program; } * Purpose: relurns this Student's program Parameters: none + Returns: String the program public String get. Program () { return this.program; * /* * Purpose: returns a String representation of this student in the form "SID:grade" * Parameters: none * Returns: String - the representation * */ public String toString() { return sID + "." + gpa + } + program; * /* * Purpose: returns true if this Student's SID equals the other student's SID * Parameters: none * Returns: boolean - true if equal, false otherwise */ public boolean equals (Student other) { return (this.sID.equals (other.SID)); } * StudentNode.java * A singly-linked student node class public class StudentNode { public StudentNode next; private Student data; public StudentNode (Student data) { this.data = data; this.next = null; } public StudentNode (Student data, StudentNode next) { this.data = data; this.next = next; } * Purpose: returns the value of this studentNode's next * Parameters: none * Returns: StudentNode - the next public StudentNode getNext() { return this.next; } /* * Purpose: set's this StudentNode's next to parameter value * Parameters: StudentNode - next * Returns: nothing */ public void setNext (StudentNode next) { this.next = next; } /* * Purpose: returns the value of this studentNode's data * Parameters: none * Returns: Student - the data public Student getData() { return this.data; } /* * Purpose: set's this StudentNode's data to parameter value * Parameters: Student - data * Returns: nothing public void setData(Student data) { this.data = data; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Database And Knowledge Base Systems

Authors: S Krishna

1st Edition

9810206208, 978-9810206208

More Books

Students also viewed these Databases questions

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago