Solution1

 package pone;

import java.util.*;

class Customer
{
private int customerId;
private String name;
private int age;
private String gender;
private ArrayList<Perfume> availablePerfumes;

public Customer(int customerId,String name,int age,String gender, ArrayList<Perfume> availablePerfumes)
{
this.customerId = customerId;
this.name = name;
this.age = age;
this.gender = gender;
this.availablePerfumes = availablePerfumes;
}


public int getCustomerId() {
return customerId;
}

public Customer setCustomerId(int customerId) {
this.customerId = customerId;
return this;
}

public String getName() {
return name;
}

public Customer setName(String name) {
this.name = name;
return this;
}

public int getAge() {
return age;
}

public Customer setAge(int age) {
this.age = age;
return this;
}

public String getGender() {
return gender;
}

public Customer setGender(String gender) {
this.gender = gender;
return this;
}

public ArrayList<Perfume> getAvailablePerfumes() {
return availablePerfumes;
}

public Customer setAvailablePerfumes(ArrayList<Perfume> availablePerfumes) {
this.availablePerfumes = availablePerfumes;
return this;
}
}

class Perfume
{
private int perfumeId;
private String brand;
private double price;
private String fragrance;

public Perfume(int perfumeId,String brand,double price,String fragrance)
{
this.perfumeId = perfumeId;
this.brand = brand;
this.price = price;
this.fragrance = fragrance;
}

public int getPerfumeId() {
return perfumeId;
}

public Perfume setPerfumeId(int perfumeId) {
this.perfumeId = perfumeId;
return this;
}

public String getBrand() {
return brand;
}

public Perfume setBrand(String brand) {
this.brand = brand;
return this;
}

public double getPrice() {
return price;
}

public Perfume setPrice(double price) {
this.price = price;
return this;
}

public String getFragrance() {
return fragrance;
}

public Perfume setFragrance(String fragrance) {
this.fragrance = fragrance;
return this;
}
}

public class Solution1
{
//findCustomerWithPerfumeBrand
public static void task1(ArrayList<Customer> cust,String inputBrand)
{
int count = 0;
for(Customer cc : cust)
{
for(Perfume pp : cc.getAvailablePerfumes())
{
if(pp.getBrand().equalsIgnoreCase(inputBrand))
{
System.out.println(cc.getName());
count++;
}
}
}
if(count == 0)
{
System.out.println("No Matching Customers found");
}
}

//calculateTotalExpenditure
public static void task2(ArrayList<Customer> cust)
{
double sum = 0;
for( Customer cc : cust)
{
for(Perfume pp : cc.getAvailablePerfumes())
{
sum = sum + pp.getPrice();
}
}
System.out.println(sum);
}

public static void main(String[] args)
{
Scanner xx = new Scanner(System.in);
ArrayList<Customer> cust = new ArrayList<>();
int n = xx.nextInt();xx.nextLine();
for(int i = 0;i < n; i++)
{
int customerId = xx.nextInt();xx.nextLine();
String name = xx.nextLine();
int age = xx.nextInt();xx.nextLine();
String gender = xx.nextLine();
int m = xx.nextInt();xx.nextLine();
ArrayList<Perfume> per = new ArrayList<>();
for(int j = 0;j < m; j++)
{
int perfumeId = xx.nextInt();xx.nextLine();
String brand = xx.nextLine();
double price = xx.nextDouble();xx.nextLine();
String fragrance = xx.nextLine();
per.add(new Perfume(perfumeId,brand,price,fragrance));
}
cust.add(new Customer(customerId,name,age,gender,per));
}
String inputBrand = xx.nextLine();
task1(cust,inputBrand);
task2(cust);
}
}



/*
2
1
alice
30
female
2
101
chanel
150.0
floral
103
Gucci
180.0
woody
2
Bob
35
Male
2
102
Dior
200.0
cirus
104
chanel
220.0
oriental
*/



Comments

Popular posts from this blog

Restaurant

TimePass

UIUXFILES