0% found this document useful (0 votes)
13 views8 pages

Java Ass 6

The document contains Java code for three applications: a bonus calculator for employees, a student pass filter, and a sales analysis tool. Each application demonstrates the use of object-oriented programming, functional interfaces, and Java streams. The code includes classes for Employee, Student, and SalesRecord, along with their respective functionalities and output displays.

Uploaded by

street28gamer
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)
13 views8 pages

Java Ass 6

The document contains Java code for three applications: a bonus calculator for employees, a student pass filter, and a sales analysis tool. Each application demonstrates the use of object-oriented programming, functional interfaces, and Java streams. The code includes classes for Employee, Student, and SalesRecord, along with their respective functionalities and output displays.

Uploaded by

street28gamer
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/ 8

NAME- RIYA DESHMANKAR

ROLL NO.-2300290100212
SECTION-C

Ques1.)
import java.util.*;
class Employee {
private String name;
private double salary;
private String type; // "Permanent" or "Contract"
public Employee(String name, double salary, String type) {
this.name = name;
this.salary = salary;
this.type = type;
}
public String getName() { return name; }
public double getSalary() { return salary; }
public String getType() { return type; }
}
@FunctionalInterface
interface BonusCalculator {
double calculateBonus(Employee e);
}

public class BonusApp {


public static void main(String[] args) {
List<Employee> employees = Arrays.asList(
new Employee("Neelakshi", 50000, "Permanent"),
new Employee("Sanvi", 40000, "Contract"),
new Employee("Vidhika", 60000, "Permanent")
);
BonusCalculator permanentBonus = e -> e.getSalary() * 0.20;
BonusCalculator contractBonus = e -> e.getSalary() * 0.10;

for (Employee e : employees) {


BonusCalculator calculator =
e.getType().equalsIgnoreCase("Permanent") ?
permanentBonus : contractBonus;
double bonus = calculator.calculateBonus(e);
System.out.println(e.getName() + " (" + e.getType() + ") Bonus: "
+ bonus);}}}
Output
Ques2.)
import java.util.*;
import java.util.stream.*;
class Student {
private String name;
private int marks;
public Student(String name, int marks) {
this.name = name;
this.marks = marks;
}

public String getName() { return name; }

public boolean isPass() {


return marks >= 40;
}
}
public class StudentApp {
public static void main(String[] args) {
List<Student> students = Arrays.asList(
new Student("Riya", 85),
new Student("Sagar", 32),
new Student("Anjali", 47),
new Student("Aman", 20)
);
System.out.println("Passed Students:");
students.stream()
.filter(Student::isPass)
.map(Student::getName)
.forEach(System.out::println);
}
}
Output

Ques3.)
import java.util.*;
import java.util.stream.*;
import java.util.Map.Entry;
class SalesRecord {
private String productName;
private String region;
private double salesAmount;

public SalesRecord(String productName, String region, double


salesAmount) {
this.productName = productName;
this.region = region;
this.salesAmount = salesAmount;
}

public String getRegion() { return region; }


public double getSalesAmount() { return salesAmount; }
}

public class SalesAnalysisApp {


public static void main(String[] args) {
List<SalesRecord> records = Arrays.asList(
new SalesRecord("Product A", "North", 6000),
new SalesRecord("Product B", "South", 3000),
new SalesRecord("Product C", "East", 7000),
new SalesRecord("Product D", "North", 8000),
new SalesRecord("Product E", "West", 2000),
new SalesRecord("Product F", "East", 10000)
);

Map<String, Double> totalSalesByRegion = records.stream()


.filter(r -> r.getSalesAmount() >= 5000)
.collect(Collectors.groupingBy(
SalesRecord::getRegion,
Collectors.summingDouble(SalesRecord::getSalesAmount)
));

System.out.println("Total Sales by Region (Descending):");


totalSalesByRegion.entrySet().stream()
.sorted(Entry.<String, Double>comparingByValue().reversed())
.forEach(e -> System.out.println(e.getKey() + ": " + e.getValue()));
}
}
Output

You might also like