- import java.util.Scanner;
- public class Solution {
- public static void main(String args[] ) throws Exception {
- /* Do not alter code in main method */
- Shirt[] shirts = new Shirt[5];
- Scanner sc = new Scanner(System.in);
- for(int i = 0;i<5;i++)
- {
- int tag = sc.nextInt();sc.nextLine();
- String brand = sc.nextLine();
- double price = sc.nextDouble();sc.nextLine();
- char g = sc.nextLine().charAt(0);
- shirts[i] = new Shirt(tag,brand,price,g);
- }
- char g = sc.nextLine().charAt(0);
- String brand = sc.nextLine();
- for(Shirt s: shirts)
- {
- System.out.println(getDiscountPrice(s));
- }
- Shirt[] result = getShirtForBrand(shirts,g,brand);
- for(Shirt s: result)
- {
- System.out.println(s.getTag()+" "+s.getPrice()+ " " + s.getBrand());
- }
- }
- private static Shirt[] getShirtForBrand(Shirt[] shirts, char g, String brand) {
- int c=0;
- int count=0;
- for(int i=0;i<shirts.length;i++) {
- if(shirts[i].getG() == g && shirts[i].getBrand().equalsIgnoreCase(brand) ) {
- count++;
- }
- }
- Shirt[] shrt=new Shirt[count];
- for(int i=0;i<shirts.length;i++) {
- if(shirts[i].getG() == g && shirts[i].getBrand().equalsIgnoreCase(brand) ) {
- shrt[c]=shirts[i];
- c++;
- }
- }
- for(int i=0;i<shrt.length;i++) {
- for(int j=i+1;j<shrt.length;j++) {
- if(shrt[i].getPrice()>shrt[j].getPrice()) {
- Shirt temp =shrt[i];
- shrt[i]=shrt[j];
- shrt[j]=temp;
- }
- }
- }
- return shrt;
- }
- private static double getDiscountPrice(Shirt s) {
- double res =0;
- if(s.getG() == 'm') {
- res=s.getPrice()-s.getPrice()*0.10;
- }
- if(s.getG() == 'f') {
- res=s.getPrice()-s.getPrice()*0.20;
- }
- if(s.getG() == 'u') {
- res=s.getPrice()-s.getPrice()*0.30;
- }
- return res;
- }
- /* implement your methods here*/
- }
- class Shirt {
- private int tag ;
- private String brand ;
- private double price ;
- private char g ;
- public int getTag() {
- return tag;
- }
- public void setTag(int tag) {
- this.tag = tag;
- }
- public String getBrand() {
- return brand;
- }
- public void setBrand(String brand) {
- this.brand = brand;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- public char getG() {
- return g;
- }
- public void setG(char g) {
- this.g = g;
- }
- public Shirt(int tag, String brand, double price, char g) {
- super();
- this.tag = tag;
- this.brand = brand;
- this.price = price;
- this.g = g;
- }
[text] jshirt
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: