-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavalVessel_code.java
128 lines (121 loc) · 3.42 KB
/
NavalVessel_code.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
NavalVessel[] navalvessel=new NavalVessel[4];
for(int i=0;i<4;i++)
{
int vesselId=sc.nextInt();sc.nextLine();
String vesselName=sc.nextLine();
int noOfVoyagesPlanned=sc.nextInt();
int noOfVoyagesCompleted=sc.nextInt();sc.nextLine();
String purpose=sc.nextLine();
navalvessel[i]=new NavalVessel(vesselId,vesselName,noOfVoyagesPlanned,noOfVoyagesCompleted,purpose);
}
int percentage=sc.nextInt();sc.nextLine();
String purpose1=sc.nextLine();
int ans1=findAvgVoyagesByPct(navalvessel,percentage);
System.out.println(ans1);
NavalVessel nav=findVesselByGrade(navalvessel,purpose1);
int pp1;
pp1=(nav.getNoOfVoyagesCompleted()*100)/nav.getNoOfVoyagesPlanned();
if(pp1==100)
{
System.out.print(nav.getVesselName()+"%Star");
}
else if(pp1>80 && pp1<=99)
{
System.out.print(nav.getVesselName()+"%Leader");
}
else if(pp1>55 && pp1<=79)
{
System.out.print(nav.getVesselName()+"%Inspirer");
}
else if(pp1>0&& pp1<55)
{
System.out.print(nav.getVesselName()+"%Striver");
}
else if(pp1==0) {
System.out.print(nav.getVesselName()+"%No Naval Vessel");
}
}
public static int findAvgVoyagesByPct(NavalVessel[] navalvessel, int percentage) {
int avg=0;
int count=0;
int pp=0;
for(int i=0;i<4;i++)
{
pp=(navalvessel[i].getNoOfVoyagesCompleted()*100)/navalvessel[i].getNoOfVoyagesPlanned();
if(pp>=percentage)
{
avg=avg+navalvessel[i].getNoOfVoyagesCompleted();
count=count+1;
}
}
int per=avg/count;
return per;
}
public static NavalVessel findVesselByGrade(NavalVessel[] navalvessel,String purpose) {
NavalVessel nava=new NavalVessel(0,null,0,0,null);
for(int i=0;i<4;i++)
{
if(navalvessel[i].getPurpose().equalsIgnoreCase(purpose)) {
nava=navalvessel[i];
}
}
return nava;
}
}
class NavalVessel{
private int vesselId;
private String vesselName;
private int noOfVoyagesPlanned;
private int noOfVoyagesCompleted;
private String purpose;
private String classification;
public int getVesselId() {
return vesselId;
}
public void setVesselId(int vesselId) {
this.vesselId = vesselId;
}
public String getVesselName() {
return vesselName;
}
public void setVesselName(String vesselName) {
this.vesselName = vesselName;
}
public int getNoOfVoyagesPlanned() {
return noOfVoyagesPlanned;
}
public void setNoOfVoyagesPlanned(int noOfVoyagesPlanned) {
this.noOfVoyagesPlanned = noOfVoyagesPlanned;
}
public int getNoOfVoyagesCompleted() {
return noOfVoyagesCompleted;
}
public void setNoOfVoyagesCompleted(int noOfVoyagesCompleted) {
this.noOfVoyagesCompleted = noOfVoyagesCompleted;
}
public String getPurpose() {
return purpose;
}
public void setPurpose(String purpose) {
this.purpose = purpose;
}
public String getClassification() {
return classification;
}
public void setClassification(String classification) {
this.classification = classification;
}
public NavalVessel(int vesselId, String vesselName, int noOfVoyagesPlanned, int noOfVoyagesCompleted,
String purpose) {
super();
this.vesselId = vesselId;
this.vesselName = vesselName;
this.noOfVoyagesPlanned = noOfVoyagesPlanned;
this.noOfVoyagesCompleted = noOfVoyagesCompleted;
this.purpose = purpose;
}
}