-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import java.util.*; | ||
public class Answer { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
Beach[] bc = new Beach[4]; | ||
for (int i = 0; i < bc.length; i++) { | ||
int a = sc.nextInt();sc.nextLine(); | ||
String b = sc.nextLine(); | ||
int c = sc.nextInt(); | ||
int d = sc.nextInt(); | ||
sc.nextLine(); | ||
bc[i] = new Beach(a,b,c,d); | ||
} | ||
String e = sc.nextLine(); | ||
int f = sc.nextInt(); | ||
int ans = findLeastRatingWithName(bc,e,f); | ||
if(ans!=0) | ||
{ | ||
System.out.println(ans); | ||
} | ||
else | ||
{ | ||
System.out.println("No beach found"); | ||
} | ||
|
||
} | ||
public static int findLeastRatingWithName(Beach[] bc, String e, int f) | ||
{ | ||
int[] rate = new int[0]; | ||
for (int i = 0; i < bc.length; i++) { | ||
if(bc[i].getName().equalsIgnoreCase(e) && bc[i].getCost()>f) | ||
{ | ||
rate = Arrays.copyOf(rate, rate.length+1); | ||
rate[rate.length-1] = bc[i].getRating(); | ||
Arrays.sort(rate); | ||
} | ||
} | ||
if(rate.length>0) | ||
{ | ||
return rate[0]; | ||
} | ||
return 0; | ||
} | ||
} | ||
class Beach | ||
{ | ||
private int id; | ||
private String name; | ||
private int rating; | ||
private int cost; | ||
public Beach(int id, String name, int rating, int cost) { | ||
this.id = id; | ||
this.name = name; | ||
this.rating = rating; | ||
this.cost = cost; | ||
} | ||
public int getId() { | ||
return id; | ||
} | ||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
public String getName() { | ||
return name; | ||
} | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
public int getRating() { | ||
return rating; | ||
} | ||
public void setRating(int rating) { | ||
this.rating = rating; | ||
} | ||
public int getCost() { | ||
return cost; | ||
} | ||
public void setCost(int cost) { | ||
this.cost = cost; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Create a class Beach with the below attributes: | ||
beachId - int | ||
beachName - String | ||
beachRating - int | ||
beachCost - int | ||
Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required. | ||
|
||
Create class Solution with the main method. | ||
Implement two static methods - findLeastRatingWithName in Solution class. | ||
|
||
findLeastRatingWithName method: | ||
----------------------------------- | ||
This method will take three input parameters - array of Beach objects and string parameter and a int parameter. The method | ||
will return the minimum rating attribute from beach objects whose name is matched with string parameter and whose amount | ||
is greater than the int parameter. If no data found of beach objects, then the method should return 0. | ||
|
||
Note : All the searches should be case insensitive. | ||
|
||
These above mentioned static methods should be called from the main method. | ||
For findLeastRatingWithName method - The main method should print the least rating from the beach array. If return 0, then | ||
you should print "No beach found". | ||
|
||
Input -> | ||
1001 | ||
Puri | ||
3 | ||
8600 | ||
1002 | ||
Digha | ||
5 | ||
6200 | ||
1003 | ||
Digha | ||
3 | ||
4000 | ||
1004 | ||
Digha | ||
4 | ||
5500 | ||
digha | ||
5000 | ||
|
||
Output -> | ||
4 |