Sorted values of the given array using lambdas

Assignment Help JAVA Programming
Reference no: EM132387933

Question 1
The following program is based on linked list operations. What will be the output when the program given below is executed?

import java.util.LinkedList; import java.util.ListIterator;
public class GraduandsList {
public static void main(String[] args)
{
LinkedList<String> graduands = new LinkedList<String>();
ListIterator<String> iter; graduands.add("William Bhullar"); System.out.println("List: "+ graduands);

graduands.addLast("Andrew Zhang"); System.out.println("List: "+ graduands);

int index = graduands.indexOf("William Bhullar"); graduands.set(index,"Sajan Tabang" ); graduands.addFirst("William Bhullar"); System.out.println("List: "+ graduands);

iter = graduands.listIterator(); iter.next();
iter.next(); iter.add("Prasad Patel");
System.out.println("List: "+ graduands);
}
}

Question 2
Write the missing lines of code and the output of the following program.

import java.util.HashSet; import java.util.Set;

public class Q2SetUnion {
static Set<Integer> setOne = new HashSet<>(); static Set<Integer> setTwo = new HashSet<>();

public static void main(String[] args) {
final Integer groupOne [] = { 2, 5, 17, 27, 7,37 };
final Integer groupTwo [] = { 3, 8, 15, 25, 5, 17};

//initialise sets
for (Integer temp: groupOne)
{
setOne.add(temp);
}
for (Integer temp: groupTwo)
{
setTwo.add(temp);
}
// Complete the following lines of code using the comments as a clue.
// Create a new set named union to store the values of the resulting union
// of the given two sets.

// implement union of the two sets.

// display the values in set named union.

Question 3
Complete the code given below to enable the following functionalities:
(a) To add all the numbers from the array ‘values' to the priority queue ‘q1'.
(b) Display the content of q1 (Hint: create a copy of the queue and use poll on the copy).
(c) Replace the number ‘2' with ‘5' in ‘q1'.

import java.util.PriorityQueue; public class PriorityQueue {
public static void main (String [] args)
{
PriorityQueue<Integer> q1 = new PriorityQueue<>();
Integer [] values = { 9, 2, 12, 7, 15};
//fill the queue q1 with elements from the array values.

// Write code to display the contents of queue q1.

// write code to replace the element ‘2' with ‘5' in q1.

} // end main
} //end class

Question 4
(a) By using the definition of Big-O, show that the running time term T(n)=100+2n+
n2 is O(n2).
(b) For the following running time expressions, what would be the order of the growth rate of each in terms of Big-O notation?
i) 2n+10n
ii) n2 + 10n log2n
iii) n+ 10√n +5

Question 5

Complete the missing lines of code in the program given below to display:
(a) Sorted values of the given array using Lambdas and streams.
(b) Display the String names in ascending order after filtering the values starting with g or less.

public class Q5LambdasAndStreams {
public static void main( String[] args )
{
int [] numbers = {14, 3, 27, 12, 7, 18, 57, 15, 8};
List<Integer> values = new LinkedList<>(); String[] names = {"Lily", "Lin", "Ann", "Bill",
"Michael", "Kay", "Sam"};
for (int n: numbers)
values.add(n);

//Dsiplay the sorted values.
// write your code

//Display names in ascending order after filtering the names strating with ‘g' or less.
// write your code

} //end main
} //end class

Question 6
Assume that a SQL server connection exists to a database named Restaurant. You are given the query to create a Table named Customers that stores customer name and customerId as primary key as shown in the incomplete code given below.
(a) Complete code to execute the given query to create the table.
(b) Use PreparedStatement to search a customer with a given name.

import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager;

import java.sql.PreparedStatement; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.Statement;
public class Q6Database {
public static void main(String[] args) {
final String MYSQL_URL ="jdbc:mysql://localhost:3306"; final String DB_URL = MYSQL_URL +"/Restaurant";
//initialise MySql usename and password final String USER_NAME ="tomm"; final String PASSWORD = "mtom0001"; Connection sqlConnection;
Statement statement; PreparedStatement searchOneCustomer;

// query string to create Customers table
final String TABLE_CUSTOMERS_QRY = "CREATE TABLE" +
"CUSTOMERS (CustomerId INTEGER not NULL" + "AUTO_INCREMENT,Name VARCHAR(30)," +
"PRIMARY KEY (CustomerId) )";

// sql driver is registered and connected to the database.
sqlConnection = DriverManager.getConnection(DB_URL,
USER_NAME, PASSWORD);
statement = sqlConnection.createStatement();

//complete the missing code to execute the query to create Customers table
If (!tblCustomersExist)
// write your code

//Write PreparedStatement to execute a query to searchOneCustomer
searchOneCustomer = // write your code
} //end main
} //end class

Question 7
The following program creates a class named GenericStack and then uses it to create a Stack of Strings. Complete the code for the method push() which takes a value of type T and adds to the elements in the GenericStack. Write code to populate the GenericStack with the values from the Array of Strings, cities given below using your push method.

import java.util.LinkedList; public class GenericStack <T> {
private LinkedList <T> elements; public GenericStack() {
elements = new LinkedList <T> ();
}

//Write code for the push method
//Use appropriate LinkedList method to add elements to the stack.
public static void main(String [] args)
{
String [] cities = {"bne", "mel", "syd", "crns" };
//Write code to create an object of type GenericStack

// Use the push method you have written to populate it with values from cities.
for (String s: cities)
// write missing code

} // end main

}// end class

Question 8
Write a recursive method, public int findSum(int n) which will recrusively calculate and return the sum of numbers 0 to n.

Question 9
What is the output from the following sequence of operations?

Queue<Integer> q = new LinkedList<>(); int a =10;
q.offer(5);
q.offer(a);
q.offer(15); System.out.println (q.peek()); q.poll();
q.offer(50);
Iterator iter = q.iterator(); while(iter.hasNext())
System.out.print(q.poll()+ " ");

Question 10
In the binary search tree shown below certain values are misplaced by not following the binary search tree rules. Correct the misplaced values.
List the values of A and B in the tree shown below so that it is a binary search tree. Manually provide the inorder, preorder and postorder traversals of the binary search tree with values of A, B, and all values correctly placed.

981_figure1.jpg

Attachment:- Term 1 Standard Examination 2018.rar

Reference no: EM132387933

Questions Cloud

Replacing an existing piece of equipment : A company is considering replacing an existing piece of equipment. The company uses an interest rate of 7%
Determine the equivalent annual cost : Determine the equivalent annual cost if the equipment is kept for 1 year, 2 years, 3 years, 4 years, 5 years or 6 years.
Find info to this group-national organization for women : Find info to this group,National Organization for Women. Research the web and other resources for information about your chosen interest group.
Experimenters wanted to know if the moon at the horizon : The experimenters wanted to know if the Moon at the horizon looked bigger than the Moon at the zenith.
Sorted values of the given array using lambdas : Sorted values of the given array using Lambdas and streams and Display the String names in ascending order after filtering the values starting with g or less.
What are the some of the problems : What are the some of the problems in trying to use fiscal and monetary policies under different exchange rate regimes?
What is the law of demand and supply : What is the law of demand and supply? What is equilibrium price?
What does the given program do : Explain how the layout manager might be used for building this GUI - What value is displayed when this program executes? What mathematical function
Construct a table showing norita : (i) Construct a table showing Norita's marginal sales per day in each city.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd