0% found this document useful (0 votes)
189 views

Fabric Set Java

The document defines a Fabric class with properties like id, name, available stock and price. It then defines methods to find the fabric with maximum price and search by name. The main method takes fabric details as input, stores in Fabric objects, finds fabric with max price and searches by given name to output details.

Uploaded by

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

Fabric Set Java

The document defines a Fabric class with properties like id, name, available stock and price. It then defines methods to find the fabric with maximum price and search by name. The main method takes fabric details as input, stores in Fabric objects, finds fabric with max price and searches by given name to output details.

Uploaded by

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

import java.io.

*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {


public static void main(String args[]) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
sc.nextLine();
Fabric[] f = new Fabric[n];
for (int i = 0; i < n; i++) {
int id = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
int availableStock = sc.nextInt();
sc.nextLine();
double price = sc.nextDouble();
sc.nextLine();

f[i] = new Fabric(id, name, availableStock, price);

String nm = sc.nextLine();

Fabric fm = findFabricWithMaximumPrice(f);
if (fm != null) {
System.out.println("Id:" + fm.id);
System.out.println("name:" + fm.name);
System.out.println("availableStock:" + fm.availableStock);
System.out.println("price:" + fm.price);
} else {
System.out.println("No Fabric found with mentioned attribute.");
}

Fabric fn = searchFabricByName(f, nm);


if (fn != null) {
System.out.println("Id:" + fn.id);
System.out.println("name:" + fn.name);
System.out.println("availableStock:" + fn.availableStock);
System.out.println("price:" + fn.price);
} else {
System.out.println("No Fabric found with mentioned attribute.");
}
}

public static Fabric findFabricWithMaximumPrice(Fabric[] f) {


if(f.length==0){
return null;
}
int l = f.length;
double mp = f[0].price;
Fabric ans = null;
for (int i = 0; i < l; i++) {
if (f[i].price >= mp) {
ans = f[i];

}
return ans;
}

public static Fabric searchFabricByName(Fabric[] f, String nm) {


int l = f.length;
for (int i = 0; i < l; i++) {
if (nm.equals(f[i].name)) {
return f[i];
}

}
return null;
}
}

class Fabric {
int id;
String name;
int availableStock;
double price;

Fabric(int id, String name, int availableStock, double price) {


this.id = id;
this.name = name;
this.availableStock = availableStock;
this.price = price;

public void setId(int id) {


this.id = id;
}

public void setname(String name) {


this.name = name;
}

public void setavaialbleStock(int availableStock) {


this.availableStock = availableStock;
}

public void setprice(double price) {


this.price = price;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy