Design Pattern Algorithm implementation

Page 1 of 1

1 Replies - 349 Views - Last Post: 02 August 2016 - 07:01 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=395878&amp;s=66f99dcae65fb4b06df3249038918851&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 SIeviN

Reputation: 0
• Posts: 2
• Joined: 02-August 16

Design Pattern Algorithm implementation

Posted 02 August 2016 - 06:18 PM

Hello,
I'm trying to implement a function to calculate the average of a few assignment grades and exam grades.
The algorithm must be able to be selected at runtime and it must be possible to add new algorithms to compute the average to the program without modifying the Student class.
A. Assignments contribute 40% of grade, the other 60% comes from tests.
B. same weights as above, but if there is two or more assignment scores, drop the lowest

I believe I should be using the strategy design pattern, but with how the classes are written, I'm lost.

In main
```Student student = new Student("John Doe");

//use first algorithm
System.out.println(student.getName() + " " + student.getAverage());

//switch to second algorithm
//code to switch to algorithm 2 here
System.out.println(student.getName() + " " + student.getAverage());

//code to switch back to algorithm 1 here

```

in Student class
```private String name;
private ArrayList<Double> assignments;
private ArrayList<Double> exams;

public String getName()
{ return name; }

public double getAverage()
{
//implement this
}

```

Is This A Good Question/Topic? 0

Replies To: Design Pattern Algorithm implementation

#2 SIeviN

Reputation: 0
• Posts: 2
• Joined: 02-August 16

Re: Design Pattern Algorithm implementation

Posted 02 August 2016 - 07:01 PM

The solution output is this, notice it doesn't have anything to prompt the user to select which algorithm to use.

John Doe 90.2
John Doe 92.3