Java
Do 68a, 68b, 68c, 68d. Show code & output.
68a.
Sample Output :
Program Code to Copy
import java.util.ArrayList; import java.util.HashSet; import java.util.stream.Collectors;
class Demo{ public static void main(String[] args) { //68a ArrayList<Employee> al = new ArrayList<Employee>(); al.add(new Employee(101,"sam",1000)); al.add(new Employee(102,"sameer",2000)); al.add(new Employee(103,"shyam",3000)); al.add(new Employee(104,"ram",4000)); al.add(new Employee(105,"ramesh",5000)); al.add(new Employee(106,"sameera",60000)); ArrayList<Integer> ids = new ArrayList(al.stream().map(x->x.getId()).collect(Collectors.toList())); ArrayList<String> names = new ArrayList(al.stream().map(x->x.getName()).collect(Collectors.toList())); ArrayList<Integer> sals = new ArrayList(al.stream().map(x->x.getSal()).collect(Collectors.toList())); System.out.println(ids); System.out.println(names); System.out.println(sals); } }
68b
Program Code Screenshot
Sample Output :
Program Code to Copy
import java.util.ArrayList; import java.util.HashSet; import java.util.stream.Collectors;
class Demo{ public static void main(String[] args) { //68a ArrayList<Employee> al = new ArrayList<Employee>(); al.add(new Employee(101,"sam",10000)); al.add(new Employee(102,"sameer",2000)); al.add(new Employee(103,"shyam",30000)); al.add(new Employee(104,"ram",4000)); al.add(new Employee(105,"ramesh",15000)); al.add(new Employee(106,"sameera",60000)); ArrayList<Employee> highSal = new ArrayList(al.stream().filter(x->x.getSal()>5000).collect(Collectors.toList())); System.out.println(highSal); } }
68c.
Program Code Screenshot :
Sample Output :
Program Code to Copy
import java.util.HashSet; class Demo{ public static void main(String[] args) { //Create hash set HashSet<Integer> ints = new HashSet<>(); //Add ints ints.add(4); ints.add(3); ints.add(4); ints.add(5); System.out.println("Integers "+ints); } }
68d.
Sample Output :
Program Code to Copy
import java.util.HashSet; import java.util.Objects; class Employee{ private int id; private String name; private int sal; public Employee(int id, String name, int sal) { this.id = id; this.name = name; this.sal = sal; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getSal() { return sal; } public void setSal(int sal) { this.sal = sal; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Employee employee = (Employee) o; return id == employee.id && sal == employee.sal && Objects.equals(name, employee.name); } //Hashcode and equals method @Override public int hashCode() { return Objects.hash(id, name, sal); } @Override public String toString() { return "Employee{" + "id=" + id + ", name='" + name + '\'' + ", sal=" + sal + '}'; } } class Demo{ public static void main(String[] args) { //68a HashSet<Employee> al = new HashSet<>(); al.add(new Employee(101,"sam",10000)); al.add(new Employee(101,"sam",10000)); al.add(new Employee(103,"shyam",30000)); al.add(new Employee(104,"ram",4000)); al.add(new Employee(103,"shyam",30000)); al.add(new Employee(106,"sameera",60000)); System.out.println(al); } }
Java Do 68a, 68b, 68c, 68d. Show code & output. public class Employee { private int...
Java Do 61a, 61b, 61c, 61d. Show Output and Code. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...
Java Programming Answer 60a, 60b, 60c, 60d. Show code & output. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return...
Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...
Given: public class ItemTest { private final int id; public ItemTest(int id) { this.id = id; } public void updateId(int newId) { id = newId; } public static void main(String[] args) { ItemTest fa = new ItemTest(42); fa.updateId(69); System.out.println(fa.id); } } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The attribute id in the ItemTest object remains unchanged. D. The attribute id in the ItemTest object is modified to the new value. E....
In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...
What is the final value of the count field? public class Person { private String name; private int age; private static int count=0; public Person(String name, int age) { this.name = name; this.age age; count++; } public static void main(String[] args) { Person a - new Person("John Doe". 35): Person b new Person("Jane Doe", 38): for(int i=0;i<5;i++) Person tempa
I need help displaying two zeroes in hours:minutes:seconds. In Java. I need some help for the time to display correctly. I want it to display double zeroes. 06:00:00 and 12:00:00. public class Clock { String name; static int uid=100; int id; int hr; int min; int sec; public Clock() { this.name="Default"; this.id=uid; this.hr=00; this.min=00; this.sec=00; uid++; } public Clock(String name, int hr, int min, int sec) { if (hr<=24 && min <=60 && sec <=60) { this.hr = hr; this.min...
JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...
What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class Inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } Java language!! // include explanation!
I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student { private String name; private double gpa; private int idNumber; public Student() { this.name = ""; this.gpa = 0; this.idNumber = 0; } public Student(String name, double gpa, int idNumber) { this.name = name; this.gpa = gpa; this.idNumber = idNumber; } public Student(Student s)...