create account

Object Oriented Programming in Java with IntelliJ Part 3 by dissgo

View this thread on: hive.blogpeakd.comecency.com
· @dissgo · (edited)
$19.18
Object Oriented Programming in Java with IntelliJ Part 3
Hello, everyone!
I'd like to share about what is and how to code object oriented programming in Java language with IntelliJ.
What is Java?
>Java is a computer programming language and computing platform.

What is IntelliJ?
>IntelliJ is an IDE created that make possible for us to code or develop something useful for people.

What is IDE?
>IDE is an Integrated Development Environment that means provide the basic tool for developers to code and test the software. Basicly, it will contain code editor, compiler and debugger.

What is OOP?
>OOP stands for Object Oriented Programming. OOP is a programming concept which applies object concept that the object is consisted of attribute and method.

Now, let's start.
**Step 1**
Install and run IntelliJ which can be downloaded at [here](http://www.jetbrains.com/idea/download/) or directly from the community at [here](http://www.jetbrains.org/display/IJOS/Download). Yes, it's officially built by community. That's why it's called as community edition from the official jetbrains web and it's free.
![1. Setup.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515221273/qmwt1cwbfu5zzb4j2yyz.png)
<center>
![1. Setup_2.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515221428/kddiixsjbzcz9ux0skav.png)
</center>
This is the old code from my [post](https://steemit.com/utopian-io/@dissgo/object-oriented-programming-in-java-with-intellij-part-2). We'll start from this.
```
private double Quiz,MidExam,LastExam;
    public Score(){
        Quiz=0;
        MidExam=0;
        LastExam=0;
    }
    public void setQuiz(double x){
        if(x>=0 && x<=100)
            Quiz=x;
    }
    public void setMidExam(double x){
        if(x>=0 && x<=100)
            MidExam=x;
    }
    public void setLastExam(double x){
        if(x>=0 && x<=100)
            LastExam=x;
    }
    public double getQuiz() {
        return Quiz;
    }
    public double getMidExam() {
        return MidExam;
    }
    public double getLastExam() {
        return LastExam;
    }
    public double getScore(){
        return 0.2*Quiz+0.3*MidExam+0.5*LastExam;
    }
```

The Complete Code on Screenshot
![1. Old.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515227768/w1roxbdv7groveeaqslx.png)

Before we continue to the code, we should know that one of the main features is inheritance in OOP.
What is inheritance?
>Inheritance is a class that get properties from another class, its attribute and its method. The top class is called as superclass or parent class and the class which is inherited from the top class is called as subclass or extended class.

Like in this case, Score is the superclass and Score2 is the subclass.
**Step 2**
Right-click on the package, then **New>Class** to create the extended class.
![2. New Class.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515229948/w3wmiezkcont0dgxnn8s.png)

Name it as you want to, but to make it easier to remember, don't name randomly or further than the name of the superclass. Like, **Score2**.
![3. Name Class.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230038/mbxdosepll4oglqwuerx.png)

New Class created.
![4. Class created.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230348/ybwxnahcjiuxj1kl9zhc.png)

Now, let's start the basic to extend the class from inheritance. Change the code in the class before to be like this. Score2 class will be able to use Score class's attributes and methods.
```
public class Score2 extends Score {
}
```

![4. Extended Class created.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230446/k6njjg1mwk5hjunjjdep.png)

Now, let's start coding.
I want to add `Exercise` attribute to make the new one for counting the score.
```
private double Exercise;
```

Why `private`? Because to prevent the value to be directly set from another class. You can check my previous post about access level at [here](https://steemit.com/utopian-io/@dissgo/object-oriented-programming-in-java-with-intellij-part-2)

Now, create the constructors. This is the constructor without parameter. You can set the value from the class directly itself. e.g : `Exercise=100;` or `Exercise=0;`, then the value will return 100 or 0.
```
public Score2(){
        super();
        Exercise=0;
    }
```

This is the constructor with parameter. You can freely set the value when the constructor's referred as an instance of every object in the tester class later. About this code `if(E>=0 && E<=100)`, I need to create the statement right here because it can be an exception or handler if the value is set lower/higher than it's supposed to be, but why don't code like that for `super(Q,M,L);`? Because it has been written in the class itself. So, I just call it here from the superclass.
```
public Score2(double Q, double M, double L, double E){
        super(Q,M,L);
        if(E>=0 && E<=100)
            Exercise=E;
    }
```

As always, we need to create getter and setter, but this won't be used if you use constructor with parameter.
What is setter?
>Setter is the method to modify or set the value of the variable.

What is getter?
>Getter is the method to get or view the value of the variable.

For example, I will create the getter and setter like this. Why we need to return or make the statement with `this` at `this.Exercise=Exercise;`? Because it declares that the `Exercise` attribute value in this class will be set with `Exercise` parameter. About this code `if(Exercise>=0 && Exercise<=100)`, it's an exception or handler if the value is set lower/higher than it's supposed to be.
```
public void setExercise(double Exercise){
        if(Exercise>=0 && Exercise<=100)
            this.Exercise=Exercise;
    }
    public double getExercise() {
        return this.Exercise;
    }
```

The last for this class. Create the function which is the same as the superclass, but with additional.
`super.getScore()+0.1*Exercise;` means you call the function in the superclass which is created before and in this new class, you add the additional calculation with the new attribute and it becomes one complete function.
```
    public double getScore(){
        return super.getScore()+0.1*Exercise;
    }
```

The Complete Code on Screenshot
![5. Score2 Code.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236945/rslquvmlpuklfzvtrcv5.png)

Now, back to the superclass. You can modify the code to be like this. It's the same thing you've done with new subclass before.
```
private double Quiz,MidExam,LastExam;
    public Score(){
        Quiz=0;
        MidExam=0;
        LastExam=0;
    }
    public Score(double Q, double M, double L){
        if(Q>=0 && Q<=100)
            Quiz=Q;
        if(M>=0 && M<=100)
            MidExam=M;
        if(L>=0 && L<=100)
            LastExam=L;
    }
    public void setQuiz(double Quiz){
        if(Quiz>=0 && Quiz<=100)
            this.Quiz=Quiz;
    }
    public void setMidExam(double MidExam){
        if(MidExam>=0 && MidExam<=100)
            this.MidExam=MidExam;
    }
    public void setLastExam(double LastExam){
        if(LastExam>=0 && LastExam<=100)
            this.LastExam=LastExam;
    }
    public double getQuiz() {
        return this.Quiz;
    }
    public double getMidExam() {
        return this.MidExam;
    }
    public double getLastExam() {
        return this.LastExam;
    }
    public double getScore(){
        return 0.2*Quiz+0.3*MidExam+0.5*LastExam;
    }
```

The Complete Code on Screenshot
![6. Score Code.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236996/e4gxeg8po8xdxlasskid.png)

Now, write the code in the tester class like this. As always, create new Object of your class you created before in this tester class first, because It will refer as an instance of every object created. This one if you use the constructor without parameter.
```
Score2 s1;
s1=new Score2();
```

You need to set the value with the setter you created before. For Example, it will be completely like this.
```
        Score2 s1;
        s1=new Score2();
        s1.setQuiz(60);
        s1.setMidExam(80);
        s1.setLastExam(90);
        s1.setExercise(100);
```

And, this one if you use the constructor with parameter. You can set directly without using setter.
```
Score2 s2;
s2=new Score2(60,80,90,100);
```

<center>
**Here is The Final Result**
![Final Result.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236541/rcgxbpi7wtuph7wt1rw8.png)
</center>

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@dissgo/object-oriented-programming-in-java-with-intellij-part-3">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , ,
properties (23)
authordissgo
permlinkobject-oriented-programming-in-java-with-intellij-part-3
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":2489216,"name":"intellij-community","full_name":"JetBrains/intellij-community","html_url":"https://github.com/JetBrains/intellij-community","fork":false,"owner":{"login":"JetBrains"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","tutorial","java","programming","opensource"],"users":["dissgo"],"links":["http://www.jetbrains.com/idea/download/","http://www.jetbrains.org/display/IJOS/Download","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515221273/qmwt1cwbfu5zzb4j2yyz.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515221428/kddiixsjbzcz9ux0skav.png","https://steemit.com/utopian-io/@dissgo/object-oriented-programming-in-java-with-intellij-part-2","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515227768/w1roxbdv7groveeaqslx.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515229948/w3wmiezkcont0dgxnn8s.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230038/mbxdosepll4oglqwuerx.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230348/ybwxnahcjiuxj1kl9zhc.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230446/k6njjg1mwk5hjunjjdep.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236945/rslquvmlpuklfzvtrcv5.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236996/e4gxeg8po8xdxlasskid.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236541/rcgxbpi7wtuph7wt1rw8.png"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1515221273/qmwt1cwbfu5zzb4j2yyz.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515221428/kddiixsjbzcz9ux0skav.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515227768/w1roxbdv7groveeaqslx.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515229948/w3wmiezkcont0dgxnn8s.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230038/mbxdosepll4oglqwuerx.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230348/ybwxnahcjiuxj1kl9zhc.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515230446/k6njjg1mwk5hjunjjdep.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236945/rslquvmlpuklfzvtrcv5.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236996/e4gxeg8po8xdxlasskid.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1515236541/rcgxbpi7wtuph7wt1rw8.png"],"moderator":{"account":"manishmike10","pending":false,"reviewed":true,"flagged":false}}
created2018-01-06 11:11:06
last_update2018-01-06 17:17:36
depth0
children7
last_payout2018-01-13 11:11:06
cashout_time1969-12-31 23:59:59
total_payout_value13.449 HBD
curator_payout_value5.735 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length8,635
author_reputation3,860,675,847,142
root_title"Object Oriented Programming in Java with IntelliJ Part 3"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id27,500,223
net_rshares2,431,179,350,616
author_curate_reward""
vote details (14)
@iamgun ·
dissgo!! Thank you, your Post. i upvoted.^^
properties (22)
authoriamgun
permlink20180107t000444440z
categoryutopian-io
json_metadata{}
created2018-01-07 00:04:45
last_update2018-01-07 00:04:45
depth1
children1
last_payout2018-01-14 00:04:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length43
author_reputation263,611,044,702
root_title"Object Oriented Programming in Java with IntelliJ Part 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id27,641,315
net_rshares0
@dissgo ·
You're welcome :)
properties (22)
authordissgo
permlinkre-iamgun-20180107t000444440z-20180110t093337790z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-01-10 09:33:39
last_update2018-01-10 09:33:39
depth2
children0
last_payout2018-01-17 09:33:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length17
author_reputation3,860,675,847,142
root_title"Object Oriented Programming in Java with IntelliJ Part 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id28,454,325
net_rshares0
@manishmike10 ·
Your contribution cannot be approved yet. See the [Utopian Rules](https://utopian.io/rules). Please edit your contribution to reapply for approval.
`We could use the code from my previous post.`
* It would be better if you specified those codes in this post.  
You may edit your post [here](https://utopian.io/utopian-io/@dissgo/object-oriented-programming-in-java-with-intellij-part-3), as shown below: 
![](https://res.cloudinary.com/hpiynhbhq/image/upload/v1509788371/nbgbomithszxs3nxq6gx.png)

You can contact us on [Discord](https://discord.gg/UCvqCsx).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authormanishmike10
permlinkre-dissgo-object-oriented-programming-in-java-with-intellij-part-3-20180106t143141714z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-06 14:31:51
last_update2018-01-06 14:31:51
depth1
children1
last_payout2018-01-13 14:31:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length615
author_reputation20,399,732,899,016
root_title"Object Oriented Programming in Java with IntelliJ Part 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id27,536,872
net_rshares0
@dissgo ·
Done @manishmike10. You can review again.
properties (22)
authordissgo
permlinkre-manishmike10-re-dissgo-object-oriented-programming-in-java-with-intellij-part-3-20180106t161946591z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["manishmike10"],"app":"steemit/0.1"}
created2018-01-06 16:19:48
last_update2018-01-06 16:19:48
depth2
children0
last_payout2018-01-13 16:19:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length41
author_reputation3,860,675,847,142
root_title"Object Oriented Programming in Java with IntelliJ Part 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id27,559,218
net_rshares0
@manishmike10 ·
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/UCvqCsx).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authormanishmike10
permlinkre-dissgo-object-oriented-programming-in-java-with-intellij-part-3-20180106t171738201z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-06 17:17:42
last_update2018-01-06 17:17:42
depth1
children1
last_payout2018-01-13 17:17:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation20,399,732,899,016
root_title"Object Oriented Programming in Java with IntelliJ Part 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id27,570,707
net_rshares0
@dissgo ·
Thanks for approval @manishmike10
properties (22)
authordissgo
permlinkre-manishmike10-re-dissgo-object-oriented-programming-in-java-with-intellij-part-3-20180106t183148065z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-06 18:31:51
last_update2018-01-06 18:31:51
depth2
children0
last_payout2018-01-13 18:31:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length33
author_reputation3,860,675,847,142
root_title"Object Oriented Programming in Java with IntelliJ Part 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id27,584,678
net_rshares0
@utopian-io ·
### Hey @dissgo I am @utopian-io. I have just upvoted you!
#### Achievements
- You have less than 500 followers. Just gave you a gift to help you succeed!
- Seems like you contribute quite often. AMAZING!
#### Suggestions
- Contribute more often to get higher and higher rewards. I wish to see you often!
- Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
#### Get Noticed!
- Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
👍  
properties (23)
authorutopian-io
permlinkre-dissgo-object-oriented-programming-in-java-with-intellij-part-3-20180107t160336840z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-07 16:03:36
last_update2018-01-07 16:03:36
depth1
children0
last_payout2018-01-14 16:03:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,504
author_reputation152,955,367,999,756
root_title"Object Oriented Programming in Java with IntelliJ Part 3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id27,791,570
net_rshares104,443,821
author_curate_reward""
vote details (1)