Solution2

 package pone;

import java.util.*;

class Customer1
{
private int customerId;
private String Name;
private int noofCycles;
private ArrayList<Cycle> cycle;

public Customer1(int customerId,String Name,int noofCycles,ArrayList<Cycle> cycle)
{
this.customerId = customerId;
this.Name = Name;
this.noofCycles = noofCycles;
this.cycle = cycle;
}

public int getCustomerId() {
return customerId;
}

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

public String getName() {
return Name;
}

public Customer1 setName(String name) {
Name = name;
return this;
}

public int getNoofCycles() {
return noofCycles;
}

public Customer1 setNoofCycles(int noofCycles) {
this.noofCycles = noofCycles;
return this;
}

public ArrayList<Cycle> getCycle() {
return cycle;
}

public Customer1 setCycle(ArrayList<Cycle> cycle) {
this.cycle = cycle;
return this;
}
}
class Cycle
{
private int cycleId;
private String cycleName;
private int price;

public Cycle(int cycleId,String cycleName,int price)
{
this.cycleId = cycleId;
this.cycleName = cycleName;
this.price = price;
}

public int getCycleId() {
return cycleId;
}

public Cycle setCycleId(int cycleId) {
this.cycleId = cycleId;
return this;
}

public String getCycleName() {
return cycleName;
}

public Cycle setCycleName(String cycleName) {
this.cycleName = cycleName;
return this;
}

public int getPrice() {
return price;
}

public Cycle setPrice(int price) {
this.price = price;
return this;
}
}

public class Solution2
{
public static void task1(ArrayList<Customer1> cust1,String input1)
{
int sum = 0 , count = 0;
for(Customer1 cc : cust1)
{
for(Cycle cy : cc.getCycle())
{
if(cy.getCycleName().equalsIgnoreCase(input1))
{
sum = sum + cy.getPrice();
count++;
}
if(cy.getPrice()<0)
{
System.out.println("Invalid Price: Price cannot be negative");
return;
}
}
}
if(count == 0)
{
System.out.println("no cycle found");
}
else System.out.println(sum);
}

public static void task2(ArrayList<Customer1> cust1,int input2)
{
int count = 0;
ArrayList<String> ans = new ArrayList<>();
for(Customer1 cc : cust1)
{
for(Cycle cy : cc.getCycle())
{
if(cy.getPrice() > input2)
{
ans.add(cc.getName());
count++;
}
}
}
if(count == 0)
{
System.out.println("No matching customer found");
}
else
{
for(String ss: ans)
{
System.out.println(ss);
}
}
}


public static void main(String[] args)
{
Scanner xx = new Scanner(System.in);
int n = xx.nextInt();xx.nextLine();
ArrayList<Customer1> cust1 = new ArrayList<>();
for(int i = 0;i < n; i++)
{
int customerId = xx.nextInt();xx.nextLine();
String customerName = xx.nextLine();
int m = xx.nextInt();xx.nextLine();
ArrayList<Cycle> cyc = new ArrayList<>();
for(int j = 0;j < m; j++)
{
int cycleId = xx.nextInt();xx.nextLine();
String cycleName = xx.nextLine();
int price = xx.nextInt();xx.nextLine();
cyc.add(new Cycle(cycleId,cycleName,price));
}
cust1.add(new Customer1(customerId,customerName,m,cyc));
}
String input1 = xx.nextLine();
int input2 = xx.nextInt();xx.nextLine();
task1(cust1,input1);
task2(cust1,input2);
}
}

/*
3
1001
c1
2
101
zeeta
12000
102
voltic
2500
1002
c2
1
201
zeeta
3000
1003
c3
2
301
zeetalx
1200
302
volticlx
2500*/

Comments

Popular posts from this blog

Restaurant

TimePass

UIUXFILES