Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1 :Write a Java program which finds the number of occurrences of an element x in a sorted array A using binary search. 1- Ask

Q1 :Write a Java program which finds the number of occurrences of an element x in a sorted array A using binary search.

1- Ask the user to enter the array elements.

2- Ask the user to enter the target to search for occurrences.

3- Write a function: BinarySearch (int[] nums, int target, boolean searchFirst) to find the first or last occurrence of a given number in a sorted integer array. If (searchFirst) is true, return the first occurrence of the number; otherwise, return its last occurrence.

Hint: First occurrence of key 3 occurs at index_a = (1) and the last occurrence of 3 occurs index_b= (4) ,and the number of occurrence is the difference between index_a and index_b.

***********************************

Q2 :A. Write a class Student which contains the following data and methods

Data:

Name (string)

ID (integer)

Level (integer)

GPA (double)

Methods:

Get and set for each data item

Print all students

B. Main class contain :

BinarySum Method:

Binary recursion method which receives an array of students, and calculate the sum of the GPA of all students then returns the sum.

Main Method:

- Create an array of 4 students then assign GPA values for each student (no need

to read information from user).

print GPA values for each student.

Compute the GPA sum of all students using method BinarySum method

Compute the average GPA of all students

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

3. Contrast relational contexts in organizations

Answered: 1 week ago

Question

LO6 Summarize various ways to manage retention.

Answered: 1 week ago

Question

LO3 Define the difference between job satisfaction and engagement.

Answered: 1 week ago