In class lab 3 - Exercise 18.3 GCD – page 729 Write a class, ComputeGCD, which will do the following: The main method will: Prompt the user for two numbers. • Call the gcd method: public int gcd (int m, int n) - The gcd method will use the definition below to recursively return the gcd of m and n: gcd(m, n) = n if m % n = gcd(m, n) = gcd(n, m % n); otherwise; 0; 40
Q: mplement the design of the Student_Tutor class that inherit from Student class so that the…
A: Algorithm : class Student definition : Step 1 : define the constructor to assign the values. Step…
Q: QUESTION 10 Which of the following is true of QuickSort? (Select all that apply) O It's average run…
A: As per guidlines we are suppose to answer first question : Answer: 10. Quicksort is a…
Q: ... 9. Write a method that checks whether all elements in the indicated column are the same.…
A: Programming instructions: Initialize the matrix with strings. Take input from the user for the…
Q: Write a program which does the following: 1. Create a class with the main() method. 2. Take a string…
A: note:- length() and indexOf() both returns indexes in numeric, you must have to use charAt() to…
Q: 11. Implement a class to represent a playing card. Your class should have the following methods:…
A:
Q: Write a recursive method called displayHashtags that accepts an integer parameter n and prints out n…
A: Answer :
Q: Develop a program in Java to demonstrate the operations of a Hash Table. Use the following class…
A: The code is below:
Q: 2. Write a Java Method that reads a list of integers from the user, then deletes all negative…
A: According to the Question below the Complete Program: Program Output:
Q: 3. Charge Account Validation Create a class with a method that accepts a charge account number as…
A: The Above code ios solved in Java Programming below:
Q: lass contains three independent static methods and contains no fields (none should be added). The…
A: It is defined as a user defined blueprint or prototype from which objects are created. It…
Q: What is the purpose of the following method? Assume that both q1 and q2 are not empty. public class…
A: The correct answer along with the explanation is given below.
Q: public class FindArrayDifference { static void arrayDifference(int a[], int b[]) {…
A: We are given a piece of code for which we need to calculate step number and time complexity.…
Q: Write in java 1. Write a program that calls these two methods as described below a. A void method…
A: The main objective of the java program,Driver.java is to create two static methods pattern and…
Q: An acronym is a word formed from the initial letters of words in a set phrase. Write a program whose…
A: 1)using split function split the words whenever u encounter a space 2)check for the words starting…
Q: Part # 1: Write a method called equallists in a class called compare. The method accepts three…
A: Java Program: import java.util.ArrayList; public class compare { public static <E>…
Q: Implement getEvens method Method Details getEvens public static int getEvens(int[] array, int[]…
A: The method getEvens takes two integer array as parameters. The first parameter in the input array…
Q: n() method for the QuickSort class. Create a queue of Item objects and sort them in increasing…
A: Basically, a class item is implemented to have all the details about an item. Then a class Queue is…
Q: Write two java methods 1)static void insertionSort(T[] array, Comparator cc){} This should run in…
A: Part1: static <T> void insertionSort(T[] array, Comparator<T> cc){} This should run in…
Q: •Write a class, ComputeGCD, which will do the following: –The main method will: •Prompt the user for…
A: Program code: //import the required packages import java.util.Scanner; //define the class GCD…
Q: The following recursive method is causing an exception because the base case is missing. This…
A: Here method print() will print element of array in reverse order. In this code we are passing last…
Q: 1)The program should be written in JAVA. Create a "Car" class that keeps car ids and prices. And…
A: The given problem is to be solved using JAVA programming language where the requirement is to have:…
Q: ite a method called samePosition in a class called StackExt that receives two parameters st1 and st2…
A: Java code :- import java.util.*; public class QueueToArray { public static void main(String[]…
Q: public class QueueEx public static void method1(ArrayQueue q1, ArrayQueue q2) { Iterator iter1 =…
A: Required: java
Q: Write a recursive method named sum0fSquares that accepts an integer parameter n and returns the sum…
A: The complete JAVA program is given below Recursion has been used No loops or data structures are…
Q: Counts the number of occurrences of the given element in the given array. * Oparam array to search *…
A: Java used to answer this question
Q: in java Write a class phone that stores Name (String) and number of friends (String), Provide…
A: Note : This program is case sensitive i did not ignore the case while searching the names //Java…
Q: 2. Write a class Comparisons whose main method tests your largest method above. • First prompt the…
A: import java.util.Scanner; class Compare3 { // defination for compare largest public static…
Q: Complete the Link class by writing methods described below. Do not use loops, or create any more…
A: the solution is given below :
Q: Implement solutions for the following methods: • getCourseSize() – returns the number of students…
A: Given Implement solutions for the following methods: • getCourseSize() – returns the number of…
Q: 1.A) The median of a set of integers is the middle-most integer in size. That is, half the integers…
A: EXPLANATION: - To find the Median, the array needs to be sorted first. If the array is having an…
Q: creat a method in (java) that do the following: This will prompt the user for initial list of…
A: A permutation is systematizing the order. Elements in ordered list are rearranged into a one-to-one…
Q: Given the following class IntNode, complete method static boolean doubled (int i, IntNode 1s) to…
A: The code snippet is given below with an output screenshot and detailed explanation
Q: Implement the following class and test its methods: Fraction |- numerator. int - denominator. int +…
A: Code: Fraction class import java.util.Scanner; class Fraction{ private int numerator; private…
Q: The following class is mutable: import java.util.Set; import java.util. HashSet; public class Mute…
A: Mutable class means whose variable we can change even after its object instantiation. In your code…
Q: 53. Write a class with two instance variables, representing an old password and a new password.…
A: Since no programming language is mentioned, I am using java Code: class Client{ private String…
Q: Write static void quickSort(T[] array, Comparator cc) Implement the version that picks pivots at…
A: Comparator Interface in Java Comparator interface is used to order the objects of user-defined…
Q: Write a program that prompts a cashier to enter each price and quantity, and then a Y for a pet or…
A: //Driver.java import java.util.Scanner; public class PetStoreDriver{ public static void…
Q: in java You are required to build a class ArithematicProblem that represent a binary arithematic…
A: Code: #include<bits/stdc++.h>using namespace std; class ArithematicProblem{public: double…
Q: The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the…
A: Please check the solution below in step 2
Q: Write a code in JAVA for storing information of Employee using array. Employee attributes for…
A: Program approach:- Then creating an array class to store the employee's objects. Using add method…
Q: Need help writing the method: getWaitlistedIDs() – returns an array of type int[], namely the ids of…
A: Note: In this question we are asked to modified getWaitlistedIDs method only in java There is a…
Q: 1. Write a method called doubleListthat takes an ArrayList of strings as a parameter and replaces…
A: 1. Java Program: Code For Copy: // import libarary import java.util.*; // main class start public…
Q: Home Task: 1. Implement the following class and test its methods: Fraction - numerator: int -…
A: Code In Java:…
Q: Given the following class IntNode, complete method static boolean doubled (int i, IntNode 1s) to…
A: I am just writing the public static boolean doubled function , and using the different code for…
Q: Write a program which does the following: 1. Create a class with the main() method. 2. Take a string…
A: /*We cannot print a normal string array using Arrays.toString(), if we create a data type words[]…
Q: An acronym is a word formed from the initial letters of words in a set phrase. Write a program whose…
A: I have given an answer in step 2.
Q: Write a client program that allows the user to add up any number of non-zero fractions. The program…
A: An object of the class Fraction is made as f_s with value as fractions.get(0). Another object of the…
Q: 1) Write a simple program whose main method will repeatedly ask the user for an integer number and…
A: The program reads the input stores it into variable. It then calls the isPrime function and stores…
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- Need help writing the method: getWaitlistedIDs() – returns an array of type int[], namely the ids of students in the waitlist. public int[] getWaitlistedIDs() { // insert solution here and modify the return statement return null; } For context public class Course { public String code; public int capacity; public SLinkedList<Student>[] studentTable; public int size; public SLinkedList<Student> waitlist; public Course(String code) { this.code = code; this.studentTable = new SLinkedList[10]; this.size = 0; this.waitlist = new SLinkedList<Student>(); this.capacity = 10; } public Course(String code, int capacity) { this.code = code; this.studentTable = new SLinkedList[capacity]; this.size = 0; this.waitlist = new SLinkedList<>(); this.capacity = capacity; }Write a Java class called ContainsInRange. This class defines a method called contains(), which takes as parameters an integer array a, an integer x, an int called start, as well as an int called end, and returns a boolean which is true if and only if x occurs in a at a position which is greater than or equal to start, and less than end. You must validate that start is less than or equal to end, and that both start and end are greater than or equal to 0, and less than or equal to a.length. Repeat the operation often.•Write a class, ComputeGCD, which will do the following: –The main method will: •Prompt the user for two numbers. •Call the gcd method: public int gcd (int m, int n) –The gcd method will use the definition below to recursively return the gcd of m and n: gcd(m, n) = n if m % n = 0; gcd(m, n) = gcd(n, m % n); otherwise; Enter the first number 10 Enter the second number 15 The greatest common divisor is 5
- Complete the following method in java that takes an array and a key(int value) that traverses the input parameter array with a nested for loop and finds the number of pairs of the numbers in the array that add up to the val(key) parameter. I'm not sure if this is correct: public static int nestedLoopsTwoSum(int[] X, int val) {int count = 0;for (int i = 0; i < X.length; i++){int k;for (k = 0; k < i ; k++){if ((X[i] + X[k]) == val){count++;}}}return count;}class TenNums {private: int *p; public: TenNums() { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = i; } void display() { for (int i = 0; i < 10; i++) cout << p[i] << " "; }};int main() { TenNums a; a.display(); TenNums b = a; b.display(); return 0;} Write a copy constructor for the above class TenNums. Make sure it performs deep copy. Group of answer choices TenNums(const TenNums& b) { p = b.p;} TenNums(const TenNums& b) { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = b.p[i];} TenNums(const TenNums b) { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = b.p[i];} TenNums(const TenNums b) { p = b.p;}pet shop wants to give a discount to its clients if they buy one or more pets and at least five other items. The discount is equal to 20 percent of the cost of the other items, but not the pets.Use a class Item to describe an item, with any needed methods and a constructor public Item(double price, boolean isPet, int quantity)An invoice holds a collection of Item objects; use an array list to store them. In the Invoice class, implement methods public void add(Item anItem)public double getDiscount()Write a program that prompts a cashier to enter each price and quantity, and then a Y for a pet or N for another item. Use a price of –1 as a sentinel. In the loop, call the add method; after the loop, call the getDiscount method and display the returned value.
- The Utilities class contains three independent static methods and contains no fields (none should be added).The Utilities class contains the following 3 static methods that you must implement:1. QWERTY – If the argument is null, the length is anything other than 6, or if the element values are outside the inclusive boundof 1 to 7 throw the IllegalArgumentException with the message "Invalid parameter". Otherwise return a char array that hasinput[0] instances of 'Q', followed by input[1] instance of 'W', ....followed by input[5] instances of 'Y'. The length ofthe returned array should be the exact size needed to accommodate all the letters (no smaller or larger).2. turnTo1D – You can assume that the parameter array has at least 1 row and all rows are int array (might be an empty int array)and the parameter delta is a positive integer. The method returns a 1D array (possibly empty array) with all the values inarray that are in the range of the inclusive bound [value – delta to value +…class TenNums {private: int *p; public: TenNums() { p = new int[10]; for (int i = 0; i < 10; i++) p[i] = i; } void display() { for (int i = 0; i < 10; i++) cout << p[i] << " "; }};int main() { TenNums a; a.display(); TenNums b = a; b.display(); return 0;} Continuing from Question 4, let's say I added the following overloaded operator method to the class. Which statement will invoke this method? TenNums TenNums::operator+(const TenNums& b) { TenNums o; for (int i = 0; i < 10; i++) o.p[i] = p[i] + b.p [i]; return o;} Group of answer choices TenNums a; TenNums b = a; TenNums c = a + b; TenNums c = a.add(b);JAVA PROGRAM Write a program that asks the user to input two integers a and b. Then create an array that has all integer from a to b. Print out the array. (Don’t forget to consider the situation of a=b, a<b, and a>b.) Example 1: Input two numbers: 6 2 Array is [6, 5, 4, 3, 2] Example 2: Input two numbers: 4 8 Array is [4, 5, 6, 7, 8] Pass the above array as a parameter to a method called average and return the average and print it out in the main method. (Do not use Math library to get the average.)
- Write a Java class called MostOftenOccurring. This class defines a method called occursMostOften(), which takes as its only parameter an array of int called a and returns an int representing the value which occurs most often in a. If there is a tie, display the value which occurs first in a among those that occur most often. Repeat the operation often.WITE JAVA CODE JUST TO THE GIVEN CODE BELOW! TESTS GIVE ERROR FOR SHRINK AND add remove 100 values ALSO, DO IT BY CHECKING THE MAIN CLASS WITHOUT CHANGING IT class Queue<T> { private T[] a = (T[]) new Object[1]; private int N = 0; public boolean isEmpty() { return N == 0; } public int size() { return N; } private void resize(int capacity) { T[] temp = (T[]) new Object[capacity]; for (int i = 0; i < N; i++) { temp[i] = a[i]; } a = temp; } public void enqueue(T item) { if (N == a.length) resize(2*a.length); a[N++] = item; } public T dequeue() { T item = a[--N]; a[N] = null; if (N > 0 && N == a.length/4) resize(a.length/2); return item; } // this method is for unit testing; don't touch public int getArraySize(){ return a.length; }} public class Main { public static void main(String[] args) { Queue<Integer> myQueue = new Queue<Integer>(); int i; i = 1; myQueue.enqueue(i);…A Java Program Write a method called samePosition in a class called StackExt that receives two parameters st1 and st2 of type ArrayStack and a third parameter pos of type int. The method returns true, if stack st1 and st2 contains the same value in position pos. Otherwise, the method returns false. Assume that both stacks st1 and st2 contain same number of elements. Assume that the position of the top element is 0 and increases by 1 for each subsequent element. The elements of both stacks st1 and st2 must remain in the original relative positions in the stacks at the end of the method. Use common stack operations only such as push, pop, peek, isEmpty, constructor and copy constructor. You can create temporary objects of type ArrayStack in your method. Example: top st1: 4 5 3 10 8 st1: 5 9 4 10 1 If the pos is 3, then both stacks contain 10 in position 3. The method returns true. If the pos is 1, then st1 contains 5 and st2…