some methods private some are not

Hi,

I was going through below link

http://www.homeandlearn.co.uk/java/more_class_methods.html

I wonder why getGrade() method is private and other methods are not private.

As it is private getGrade() is being called by separate method examGrade() method using this.getGrade ()

I feel it is bit round about approach.

i was not able to copy source code to run. How do i copy and then paste to eclipse?

please advise
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
As soon as I read the title I knew this was a gudii9 question.
gurpsbassiCommented:
Go and find a better tutorial on encapsulation. The you are using is rubbish. Try oracle.
phoffric\Commented:
>>  How do i copy and then paste to eclipse
Much of the code on this site are pictures. In IE, right-clicking on the code gives a popup, and one of the options is Save Picture As. You can copy some of the code, such as:
String examGrade(int aScore) {

Exam_Grade = this.getGrade( aScore) ;
return Exam_Grade;
}
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

phoffric\Commented:
>> I wonder why getGrade() method is private and other methods are not private.
>> I feel it is bit round about approach.

I think they are just trying to introduce topics in a haphazard round about approach. I wouldn't make too much of it nor try to use their teaching style as a guideline on good design practices. Their point is:
Notice that this method is private. Just like field variables, making a method private means it can only be seen inside of this class. It can't be seen by the ExamDetails class.
phoffric\Commented:
Since gurpsbassi recommended Oracle Java learning sites, here is the link:
https://docs.oracle.com/javase/tutorial/

Here is a free Coursera course that begins in a couple of days:
Object Oriented Programming in Java
https://www.coursera.org/learn/object-oriented-java
When you enroll, to get the course for free, select
Join the course
Full Course - No Certificate

Here is their Syllabus:
Week 1

Welcome and Project Overview: Visualizing Data

Objects, Memory Models, and Scope
PreviewAbout this course
Getting started with the project
Welcome
Object design: constructors, instance variables, methods
Memory models
Scope
Check your knowledge
Quiz: Programming Assignment Quiz (Do programming assignment FIRST)
Quiz: Objects, memory models, and scope

Week 2

Graphical output: Creating GUIs and Displaying Data
Welcome 
Creating GUIs using PApplet
Unfolding Maps
Check Your Knowledge
Quiz: Programming Assignment Quiz (Do programming assignment FIRST)

Week 3

Inheritance
Welcome
Inheritance
Polymorphism
Check Your Knowledge
Quiz: Programming Assignment Quiz (Do programming assignment FIRST)

Week 4

GUIs: Responding to User Events
Welcome
Event-Driven Programming
Check Your Knowledge
Quiz: Programming Assignment Quiz (Do programming assignment FIRST)

Week 5

Searching and Sorting: From Code to Algorithms
Welcome
Searching
Basic Sorting
Check Your Knowledge
Quiz: Programming Assignment Quiz (Do programming assignment FIRST)
Assignment: Programming Assignment Extension Peer Review

Week 6

Finishing Up
Finishing the Project and Looking Back

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
phoffric\Commented:
>> i was not able to copy source code to run
If you want to master a language, then I suggest that you type a sample program in and deal with your typos by trying to understand the sometimes cryptic error messages that you get. Learning how to debug a program on your own without bothering your colleagues in the workplace is one of the important steps in becoming a professional. Tracking down the cause of the error message will also force you to think a bit more about what you typed in.
Jim CakalicSenior Developer/ArchitectCommented:
You're right. The getGrade method doesn't offer anything as examGrade simply delegates to it.

A better example of a private method might have been a refactoring of the "between" logic in the if/else structure:

private boolean between(int score, int loBound, int hiBound) {
    return score >= loBound && score <= hiBound;
}

...
if (between(score, 0, 10) 
    examGrade = "E";
else if (between(score, 11, 20)
    examGrade = "D";
...

Open in new window

Not saying that's how I'd do it. Just a "better" example of using a private method.

Regards,
Jim
gudii9Author Commented:
thank you for the links. I will explore them
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.