0% found this document useful (0 votes)
30 views7 pages

Java 8.1 Assesment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views7 pages

Java 8.1 Assesment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

package SurpriseTest;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

import java.util.HashSet;

import java.util.Iterator;

import java.util.LinkedList;

import java.util.List;

import java.util.function.Predicate;

public class SurpriseTest //(Main Class)

String city;

SurpriseTest(String eCity)

city = eCity;

……………………………………………………………………………………………………………………………………………

//Q.2 ArrayList Demonstrat

public static void main(String[] args)

ArrayList al = new ArrayList();

al.add(10);

al.add(20);

al.add(30);

System.out.println(al);

Iterator i = al.iterator();

while(i.hasNext())
{

System.out.println(i.next());

…………………………………………………………………………………………………………………………………………………………..

//Q.3 LinkedList Demonstrat

public static void main(String[] args)

LinkedList ll = new LinkedList();

ll.add(30);

ll.add(10);

ll.add(20);

System.out.println(ll);

Iterator j = ll.iterator();

while(j.hasNext())

System.out.println(j.next());

………………………………………………………………………………………………………………………………………………………

Q.4 HashSet Demonstrat

HashSet hs = new HashSet();

hs.add("HTML");

hs.add("CSS");

hs.add("JS");

System.out.println(hs);

Iterator k = hs.iterator();

while(k.hasNext())

{
System.out.println(k.next());

……………………………………………………………………………………………………………………………………………………

// Ques 6
package SurpriseTest;

import java.util.Scanner;

public class Que9_2


{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter id");
int id = sc.nextInt();
Que9_1 s = new Que9_1();
String s1 = s.getUserNameById(id);

if(s1 != null)
{
System.out.println(s1.toUpperCase());
}
else
{
System.out.println("Error");
}

…………………………………………………………………………………………………………………………………………

// Q.7

package SurpriseTest;

import java.util.ArrayList;

import java.util.List;

import java.util.function.Predicate;

public class Que7

{
String name;

String accType;

String city;

Que7(String eName, String eAccType, String eCity)

name = eName;

accType = eAccType;

city = eCity;

public String getName() {

return name;

public void setName(String name) {

this.name = name;

public String getAccType() {

return accType;

public void setAccType(String accType) {

this.accType = accType;

public String getCity() {

return city;

public void setCity(String city) {

this.city = city;

}
public static void main(String[] args)

List<Que7> ll = new ArrayList<Que7>();

ll.add(new Que7("jayesh","savings","pune"));

ll.add(new Que7("payal","savings","pune"));

ll.add(new Que7("shilpa","cureent","pune"));

ll.add(new Que7("komal","savings","pune"));

ll.add(new Que7("shradhha","FD","pune"));

Predicate<Que7> pe1 = p1 -> p1.city=="pune";

Predicate<Que7> pe2 = p2 -> p2.accType=="savings";

Predicate<Que7> pe3 = pe1.and(pe2);

for(Que7 e : ll )

if(pe3.test(e))

System.out.println(e.name);

……………………………………………………………………………………………………………………………………………………..

Q.8
package SurpriseTest;
import java.util.function.Supplier;
public class Que8
{
public static void main(String[] args)
{
Supplier<String> s = () ->
{
String otp =" ";
for(int i=1; i<=5;i++)
{
otp = otp +(int)(Math.random()*10);
}
return otp;
};
System.out.println(s.get());
}
}
……………………………………………………………………………………………………………………………………………………………………………………………..
Q.9 (Class 1)
package SurpriseTest;

public class Que9_1


{
int id;
public String getUserNameById(Integer id)
{
if(id==100)
{
return "HTML";
}
else if(id==101)
{
return "CSS";
}
else if(id == 102)
{
return "HTML";
}
else
{
return null;
}
}
public char[] toUpprCase() {
// TODO Auto-generated method stub
return null;
}

}
…………………………………………………………………
Que 9 (Class 2)
package SurpriseTest;

import java.util.Scanner;

public class Que9_2


{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter id");
int id = sc.nextInt();
Que9_1 s = new Que9_1();
String s1 = s.getUserNameById(id);

if(s1 != null)
{
System.out.println(s1.toUpperCase());
}
else
{
System.out.println("Error");
}

You might also like