2022-01-24 17:53:21
package com;
import java.util.Scanner;
public class ToyDemo {
public static void main(String[] args) {
Scanner s = new Scanner ( System.in);
Toy one = new Toy();
System.out.println("Enter a string");
Toy one= new one.name = in.nextLine();
Toy two = new Toy("banana","fruits",10,2);
Toy three = new Toy("dog","animal",800,50);
Toy four = new Toy("buffalo","animal",8000,250);
System.out.println(" The Toy with least price is " +
getLeastPriceToy(one, two, three, four, "animal"));
}
public static String getLeastPriceToy(Toy one,Toy two,Toy three,Toy four,String category) {
if(one.getCategory().equals(category))
Toy to = one;
if(two.getPrice()>to.getPrice())
to = two;
if(category.equals("animal"))
Toy to=three;
if(four.getPrice()>to.getPrice())
to = four;
return to.getName();
}
}
public class Toy{
private String name;
private String category;
private double price;
private double discount;
public Toy(String name, String category, double price, double discount){
this.name = name;
this.category = category;
this.price = price;
this.discount = discount;
Java
TOY Code TCS Today IRA
Telegram - t.me/codingsolution_IT
12.7K views14:53