Tumgik
codr101-blog · 12 years
Text
Codeacademy - Javascript // Functions and Return // 2. Return keyword
//Parameter is a number, and we do math with that parameter var timesTwo = function(number) {     return number * 2; }; // call timesTwo here var newNumber = timesTwo(5); console.log(newNumber);
1 note · View note
codr101-blog · 12 years
Text
The Art and Science of Java: Chapter 3 - Excercise 8 solution
/* * File: MilosCalculations_8.java * Solution for: The Art and Science of Java by Eric Roberts - Chapter 3 Exercise 8 * --------------------- * This application computes the average out of four integers */ package com.aus.ch3.solutions; import acm.program.ConsoleProgram; public class AverageOutOfFour_8 extends ConsoleProgram { public void run(){ setSize(500, 200); println("This application computes the average out of four integers"); int i1 = readInt("Please enter integer 1:" ); int i2 = readInt("Please enter integer 2:" ); int i3 = readInt("Please enter integer 3:" ); int i4 = readInt("Please enter integer 4:" ); int result = i1 + i2 + i3 + i4; double average = result / 4.0; println(" The average out of " + result + " is " + average); } }
0 notes
codr101-blog · 12 years
Text
The Art and Science of Java: Chapter 3 - Excercise 7 solution
/* * File: metricToO.java * Solution for: The Art and Science of Java by Eric Roberts - Chapter 3 Exercise 6 * --------------------- * The user can input a weight in kilograms. * The application then displays the corresponding weight in pounds and in ounches. */ package com.aus.ch3.solutions; import acm.program.ConsoleProgram; public class MetricToOunces_7 extends ConsoleProgram { public void run(){ setSize(400, 150); println("This application converts metric weight from kilograms to pounds and ounces"); double kilo = readDouble("Enter weight in kilo: "); double pounds = toPounds(kilo); double ounches = toOunches(kilo); println(kilo + " kilograms are equal to " + pounds + " pounds" ); println(kilo + " kilograms are equal to " + ounches + " ounches " ); } /** * converts from kilograms to ounches * * @param kilo weight in kilograms * @return weight in ounches */ private double toOunches(double kilo) { double ounches = kilo * 16; return ounches; } /** * converts from kilograms to pounds * * @param kilo weight in kilograms * @return weight in pounds */ private double toPounds(double kilo) { double pounds = kilo * 2.2; return pounds; } }
0 notes
codr101-blog · 12 years
Text
The Art and Science of Java: Chapter 3 - Excercise 6 solution
/* * File: MilosCalculations_6.java * Solution for: The Art and Science of Java by Eric Roberts - Chapter 3 Exercise 6 * --------------------- * The application displays Milos calculations from the Book "The Phantom Tollbooth" * according to Milos calculations the calculation work out to zero. * The actual solution differs from the one the application gives, using * the java precedence rules */ package com.aus.ch3.solutions; import acm.program.ConsoleProgram; public class MilosCalculations_6 extends ConsoleProgram { public void run(){ setSize(300 , 100); double intValues = 4 + 9 - 2 * 16 + 1 / 3 * 6 - 67 + 8 * 2 - 3 + 26 - 1 / 34 + 3 / 7 + 2 - 5; println("int values: " + intValues); double doubleValues = 4.0 + 9.0 - 2.0 * 16.0 + 1.0 / 3.0 * 6.0 - 67.0 + 8.0 * 2.0 - 3.0 + 26.0 - 1.0 / 34.0 + 3.0 / 7.0 + 2.0 - 5.0; println("double values: " + doubleValues); } }
0 notes
codr101-blog · 12 years
Text
The Art and Science of Java: Chapter 3 - Excercise 5 solution
/* * File: FahrenheitToCelsius_5.java * Solution for: The Art and Science of Java by Eric Roberts - Chapter 3 Exercise 5 * --------------------- * The user can input the temperatur in degrees Fahrenheit. * The application will then display the corresponding value * in degrees Celsius. */ package com.aus.ch3.solutions; import acm.program.ConsoleProgram; public class FahrenheitToCelsius_5 extends ConsoleProgram { public void run(){ setSize(400, 200); println("This application converts Fahrenheit to Celsius"); double fahrenheit = readDouble("Enter Fahrenheit: "); double celsius = toCelsius(fahrenheit); println("Celsius equivalent: " + celsius); } /** * converts fahrenheit to celsius * * @param fahrenheit the temperature in degrees fahrenheit * @return the temperature in degrees celsius */ private double toCelsius(double fahrenheit) { double celsius = (5/9.0) * ( fahrenheit - 32 ); return celsius; } }
1 note · View note
codr101-blog · 12 years
Text
The Art and Science of Java: Chapter 3 - Excercise 4 solution
/* * File: CircleArea_4.java * Solution for: The Art and Science of Java by Eric Roberts - Chapter 3 Exercise 4 * --------------------- * The user can input the radius of a circle and the application then * computes the area */ package com.aus.ch3.solutions; import acm.program.ConsoleProgram; public class CircleArea_4 extends ConsoleProgram { public void run(){ setSize( 400, 200); println("This application will calculate the area of a circle"); double radius = readDouble("Enter the radius of the circle in Cm: "); double circleArea = circleArea(radius); println("The radius is: " + circleArea + "Cms^2"); } /** * calculates the area of a circle * * @param radius the radius of the circle * @return the area of the circle */ private double circleArea(double radius) { double circleArea = Math.PI * Math.pow(radius, 2); return circleArea; } }
1 note · View note
codr101-blog · 12 years
Text
The Art and Science of Java: Chapter 3 - Excercise 2 and 3
/* * File: Interest_2.java * Solution for: The Art and Science of Java by Eric Roberts - Chapter 3 Exercise 2 * --------------------- * This application calculates the account balance for any number of years bases on * data the user inputs like: start balance, interest rate, and the years of interest. * * The application assumes that there are no depositions or withdrawals made. */ package com.aus.ch3.solutions; import acm.program.ConsoleProgram; public class Interest_2 extends ConsoleProgram { public void run() { setSize(400, 200); println("Interest calculation Program"); double start = readDouble("Enter starting balance: "); double interest = readDouble("Enter anual interest rate: "); int years = readInt("Enter years to calculate interest: "); double balance = start; for (int i = 0; i < years; i++) { balance = compute(balance, interest); int printyear = i + 1; println("Balance after year " + printyear + ": " + balance); } } /** * calculates the balance for the next year * * @param start * the balance to start the computation (balance at january of * the year) * @param interest * at which rate the interest is calculated * @return balance after one year */ private double compute(double start, double interest) { double balance = start * (1 + (interest / 100)); return balance; } }
0 notes
codr101-blog · 12 years
Photo
Tumblr media
Hi there ;)
As I searched a good source to increase my coding skills I discovered the great online courses iTunesU has to offer! Especially the course CS106A - programming Methodology is an excellent course for everyone to start with! This course focuses on the programming language Java and is accompanied by the Book The Art and Science of Java by Eric Roberts. The biggest disadvantage with the book is, that there are no solutions for the coding excercises provided and it seems that, especially for the latter chapters, the solutions are difficult to find on the internet. But fear not because I plan to publish the solutions I have written while finishining the book on my blog here on tumblr!
0 notes