0% found this document useful (0 votes)
9 views4 pages

Code Snippets, Coding Tips, Coding Questions, Etc

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Code Snippets, Coding Tips, Coding Questions, Etc

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Package practice.

demo;

Public class TestScores {

//Default Constructor
TestScores() {
}

//All-arg Constructor
TestScores(float ScoreTest1, float ScoreTest2, float ScoreTest3) {
}

float scoreTest1;
float scoreTest2;
float scoreTest3;
float avgScore;

//Setters (Set Methods a.k.a. Mutator Methods)


public void setScoreTest1(scoreTest1) {
this.scoreTest1= scoreTest1;
}

public void setScoreTest1(scoreTest2) {


this.scoreTest2= scoreTest2;
}

public void setScoreTest1(scoreTest3) {


this.scoreTest3= scoreTest3;
}

//Getters (Get Methods a.k.a. Accessor Methods)


public float getScoreTest1() {
return this.ScoreTest1;
}

public float getScoreTest2() {


return this.ScoreTest2;
}

public float getScoreTest3() {


return this.ScoreTest3;
}

//Method to find average score of the three tests


public float calcAvg(float ScoreTest1, float ScoreTest2, float ScoreTest3) {
System.out.println(return ((ScoreTest1 + ScoreTest2 + ScoreTest3) / 3));
}

}
Public class CalcTestAverage {
public static void main(String[] args) {
TestScores TestScoreObj = new TestScores();
Scanner sc = new Scanner(System.in);

while(sc.nextLine()!=null) {
System.out.println(“Enter the Score for Test-1:”);
TestScoreObj.setTestScore1(sc.nextInt());

System.out.println(“Enter the Score for Test-1:”);


TestScoreObj.setTestScore2(sc.nextInt());

System.out.println(“Enter the Score for Test-1:”);


TestScoreObj.setTestScore3(sc.nextInt());
}

float score1 = TestScoreObj.getTestScore1();


float score2 = TestScoreObj.getTestScore2();
float score3 = TestScoreObj.getTestScore3();

TestScoreObj.calcAvg(score1,score2,score3);

if(sc!=null) {
sc.close();
}

}
}

###############################

This is from my experience ,


1.Don’t think about DP first(infact lets forget whats a DP is) ..try to solve the problem
with a Recursive solution first
2.If you find a recursive solution , then you are 80% done . if you didnt find a
recursive solution GOTO step-1 else GOTO step-3 .
3.Now formulate a tree based on the recursive method . This should be simple and
tricky . Just take a small input and draw all recursion in the form of a tree . (state of
each node is the input parameter to the function)
4.Now see Which Nodes in the above tree are same , i.e which are the nodes for
which the input parameters are the same .
5.If you are still stuck to reach this step or very slow , GOTO step-3 . (Remember slow
and steady wins the race !!)
6.Now Try thinking How can you calculate the result of such nodes whose input
parameters are same and reuse . if the result depends upon 3 input parameters, then
you have to store it in a 3 dimensional array .
7.Once you figure out a the above point to do , you are 95% done . If not GOTO step-
6.
8.Now Fucking code it ..if still stuck REPEAT 8
9.The END

##############################

App: Telegram
Group/Channel: Java Discusssion

######################
######################

You might also like