Wednesday, March 25, 2020

Socraric Method Essays - Socratic Dialogues, Dialogues Of Plato

Socraric Method The Socratic Method of philosophy is basically a series of question leading to an answer. In order for this method to work though, two conditions must be met. The first one is that the interlocutor has to say what he believes. The second is that the answers must be kept short. Here is a classic example of how this method works. It is a dialogue between Socrates and Euthyphro. The thesis is What is dear to the gods is pious, what is not is impious. Next Socrates gets Euthyphro to agree to the following points. The first point is that piety and impiety are opposite. The next point is that the gods are in a state of discord. The next is that they are in discord over what is just and what is unjust. They have no set unit to measure it by. The next point is that the different gods consider different things to be just and unjust. From there he goes on to agree that some things are both just and unjust. Finally, he agrees that some things can be both god loved and god hated. The same things would then be both pious and impious according to the argument above. The way that this argument relates to the rest of the Euthyphro starts back at the beginning of the story. Socrates sees Euthyphro standing by the courthouse and naturally asks why he is there. Euthyphro explains that he is the prosecutor in a murder trial. It turns out that it is his father that he is prosecuting for the murder of a murderer. He laments to Socrates that his family and friends believe that his doing this is impious, but he believes that they are mistaken and this reveals their ignorance of piety. Since Socrates is Socrates, this naturally leads him to ask just exactly what piety is. This argument is the first of three arguments in the Euthyphro that try to answer the question of what exactly piety is. The next arguments are that the pious are what all the gods love, and the opposite, what all the gods hate, is the impious. The third argument is that piety is part of justice, but it is a weak argu ment and it really never gets fully explained. Philosophy Essays

Friday, March 6, 2020

Generating Unique Random Numbers Using Java

Generating Unique Random Numbers Using Java When you generate random numbers its often the case that each generated number number must be unique. A good example is picking lottery numbers. Each number picked randomly from a range (e.g., 1 to 40) must be unique, otherwise, the lottery draw would be invalid. Using a Collection The easiest way to pick unique random numbers is to put the range of numbers into a collection called an ArrayList. If youve not come across an ArrayList before, its a way of storing a set of elements that dont have a fixed number. The elements are objects that can be added to or removed from the list. For example, lets make the lottery number picker. It needs to pick unique numbers from a range of 1 to 40. First, put the numbers into an ArrayList using the add() method. It takes the object to be added as a parameter: import java.util.ArrayList;public class Lottery { public static void main(String[] args) { //define ArrayList to hold Integer objects ArrayList numbers new ArrayList(); for(int i 0; i 40; i) { numbers.add(i1); } System.out.println(numbers); }} Note that we are using the Integer wrapper class for the element type so that the ArrayList contains objects and not primitive data types. The output shows the range of numbers from 1 to 40 in order: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40] Using the Collections Class A utility class called Collections offers different actions that can be performed on a collection like an ArrayList (e.g., search the elements, find the maximum or minimum element, reverse the order of elements, and so on). One of the actions it can perform is to shuffle the elements. The shuffle will randomly move each element to a different position in the list. It does this by using a Random object. This means its a deterministic randomness, but it will do in most situations. To shuffle the ArrayList, add the Collections import to the top of the program and then use the Shuffle static method. It takes the ArrayList to be shuffled as a parameter: import java.util.Collections;import java.util.ArrayList;public class Lottery {public static void main(String[] args) {//define ArrayList to hold Integer objectsArrayList numbers new ArrayList();for(int i 0; i 40; i){numbers.add(i1);}Collections.shuffle(numbers);System.out.println(numbers);}} Now the output will show the elements in the ArrayList in a random order: [24, 30, 20, 15, 25, 1, 8, 7, 37, 16, 21, 2, 12, 22, 34, 33, 14, 38, 39, 18, 36, 28, 17, 4, 32, 13, 40, 35, 6, 5, 11, 31, 26, 27, 23, 29, 19, 10, 3, 9] Picking the Unique Numbers To pick the unique random numbers simply read the ArrayList elements one by one by using the get() method. It takes the position of the element in the ArrayList as a parameter. For example, if the lottery program needs to pick six numbers from the range of 1 to 40: import java.util.Collections;import java.util.ArrayList;public class Lottery {public static void main(String[] args) {//define ArrayList to hold Integer objectsArrayList numbers new ArrayList();for(int i 0; i 40; i){numbers.add(i1);}Collections.shuffle(numbers);System.out.print(This weeks lottery numbers are: );for(int j 0; j 6; j){System.out.print(numbers.get(j) );}}} The output being: This weeks lottery numbers are: 6 38 7 36 1 18