E-VERSE

 

Greedy Algorithms

Hello! Today, I did a practice problem with the language C. I had to write a ‘greedy’ algorithm for giving sums of money at cashiers, with hypothetic, globally-accepted notes of 0.25, 0.10, 0.05 and 0.01 dollars. The code would calculate the minimum number of coins or notes for every transaction. for example, a transaction of 0.25 dollars would involve a minimum of 1 coin, and a transaction of 23.56 dollars would have a minimum number of 96 coins.

Code:

Screen Shot 2017-11-28 at 10.11.03 PM


Hey There!! The following code is an example of class inheritance in Java. Class inheritance may come in handy when you need a few different classes to have some similar properties, you can use a parent class in that case. In this code, if I call dab.start and dab.stop, I don’t have to include an additional line of code elsewhere and in big codes, it really matters to arrange the code properly and save space.

Screen Shot 2017-05-28 at 9.54.43 PM


Hello! I finally wrote a 65 line code in java centred on objects. it was pretty difficult and took me almost two hours. My code is based on an interview form. It asks the user for his name, where he lives, what he is strong at, age, years of experience and number of projects he has completed in the past. Then, it prints all the data to the screen and calculates the years left for the user’s retirement by subtracting his age from the average retirement age in the country. Then, the computer generates a random integer between 1 and 100, the integer is the percentage of the person becoming successful. This is obviously based on luck. I have used different methods for text and integer input. The code for determining years left for retirement and success percentage are in different methods too. In all, there are four methods in my code. For user input, I’ve used java.util.Scanner and for generating random values I’ve used java.util.Random. Before printing the success chance, I have used a for loop to print results in 10, results in 9, results in 8 and so on. To avoid everything being printed quickly onto the screen, I decided to use Thread.sleep.

Screen Shot 2017-05-24 at 1.41.04 PMScreen Shot 2017-05-24 at 1.41.16 PM

Advertisements

2 thoughts on “E-VERSE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s