-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRocket.java
More file actions
73 lines (65 loc) · 1.74 KB
/
Rocket.java
File metadata and controls
73 lines (65 loc) · 1.74 KB
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
import java.util.*;
import java.lang.*;
import java.io.*;
public class Rocket implements SpaceShip
{
int weight; //weight of item
int cost;
int maxCargo;
int currentWeight; // current weight in the rocket
double totalWeight;
public Rocket(int weight, int cost, int maxCargo)
{
this.weight = weight;
this.cost = cost;
this.maxCargo = maxCargo;
this.currentWeight = weight;
}
public int getWeight(){
return weight;
}
/*
public int getCurrentWeight(){
return currentWeight;
}
public int setCurrentWeight(int weight1){
return this.currentWeight+weight1;
}
*/
public int getMaxCargo(){
return maxCargo;
}
public int getCost(){
return cost;
}
@Override
public boolean launch()
{
return true;
}
@Override
public boolean land()
{
return true;
}
@Override
public boolean canCarry(Item thing) {
if(thing.getWeight() + currentWeight > maxCargo)
{
System.out.println("weight " + thing.getWeight() + " current Weight " + currentWeight + " Max weight " + maxCargo);
System.out.println("Can not carry this item : "+ thing.getName() + "having weight : "+ thing.getWeight());
return false;
}
else
return true;
}
@Override
public void carry(Item item)
{
System.out.println("weight " + item.getWeight() + " current Weight " + currentWeight + " Max weight " + maxCargo);
System.out.println("Carrying item : "+ item.getName()+ "having weight : "+ item.getWeight());
//item.setCurrentWeight(item.getWeight());
this.currentWeight += item.getWeight();
System.out.println("currentWeight : "+ currentWeight);
}
}