I had been with
Useful links from the Professor – 2
Level 2 Lesson 10
Getting started with classes: writing your own classes, constructors
&
Methods, method parameters, interaction and overloading
In Methods and method parameters Topic
There is an example of Truck and Bridge Officer, I tried to combined all the
3 modules(class Truck, class BridgeOfficer, and the main()method) to make it exeutable.
But everything just got messed up.
CAN ANYONE HELP ME What TO PUT Where, How & Why ?
TAKING CARE OF SMALL THINGS NOT TO BE LEFT UNEXPLAINED.
The Code Snippets Given as Follows:-
#1
public class Truck {
int length;
int width;
int height;
int weight;
public int getVolume() {
int volume = length * width * height;
return volume;
}
}
#2
public class BridgeOfficer {
int maxWeight;
public BridgeOfficer(int normalVolume) {
this.maxWeight = normalVolume;
}
public boolean checkTruck(Truck truck) {
if (truck.weight > maxWeight) {
return false;
} else {
return true;
}
}
}
#3
public static void main(String[] args) {
Truck first = new Truck();
first.weight = 10000;
Truck second = new Truck();
second.weight = 20000;
BridgeOfficer officer = new BridgeOfficer(15000);
System.out.println("Truck 1! Can I go, officer?");
boolean canFirstTruckGo = officer.checkTruck(first);
System.out.println(canFirstTruckGo);
System.out.println();
System.out.println("Truck 2! And can I?");
boolean canSecondTruckGo = officer.checkTruck(second);
System.out.println(canSecondTruckGo);
}
YOUR KIND CONSIDERATION WILL MAKE ME UNDERSTAND PROGRAMS ARRANGEMENT (THAT IS ITS GRAMMAR IN SOURCE FILE) &ITS FLOW WHICH IS MY TOUGHEST STUFF FOR NOW.
Thank You
I want to make this program executable. Please Provide HINTS ONLY
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Misiu
2 November 2020, 01:33
In IntelliJ:
1. Create new project:
File --> New --> Project...
Next, next, ...
Last window: name of the project - eg. "MyProject"
Monit: choose current or new window, as you wish, I suggest new
2. Unwind "> MyProject", should be in left window under File (third line)
3. Right mouse button on "src" --> New --> Java Class
Put name "Truck"
Into this class paste content of Truck class (#1)
4. Right mouse button on "src" --> New --> Java Class
Put name "BridgeOfficer"
Into this class paste content of BridgeOfficer class (#2 and #3)
5. Run BridgeOfficer class
0
Dinesh
2 November 2020, 18:42
Why not without ID. I think it will help me much more understandable without ID for me at this level.
0