Skip to main content

My First Control Structure in Java

Here is my first original program, written after 5 days of learning java. The goal was to include a looping control structure with decision making paths (if/else).
____________________________________________________________________
import java.util.Scanner;

public class AverageTemp 
{
//Calculates the average temperature of weekdays in centigrade 

public static void main(String[] args) 
{
Scanner keyboard = new Scanner (System.in);

double monday, tuesday, wednesday,thursday,friday;
char option;

//User input for five weekdays
do
{
System.out.println ("What was the average temperature on Monday?:");
monday = keyboard.nextDouble();
System.out.println ("What was the average temperature on Tuesday?:");
tuesday = keyboard.nextDouble();
 System.out.println ("What was the average temperature on Wednesday?:");
wednesday = keyboard.nextDouble();
System.out.println ("What was the average temperature on Thursday?:");
thursday = keyboard.nextDouble();
System.out.println ("What was the average temperature on Friday?:");
friday = keyboard.nextDouble();

double average = (monday + tuesday + wednesday + thursday + friday)/5;

System.out.println ("The average temperature this week was: " + average);

//Decision Tree comments on temperature

if (average >= 38)
{ System.out.println("Wow, that is hot!");
}

else if (average <= -10)
{ System.out.println ("Brrr!");
}

else 
{ System.out.println ("That's all right.");
}
//option to continue or end program

System.out.println ("Enter Y to continue or N to quit: ");
option = keyboard.next().charAt(0);

while (option == 'Y' || option == 'y');

}
}

Comments

Popular posts from this blog

Einstein's Logic Puzzle (SPOILER ALERT!)

On Monday I began working through a Discrete Math textbook in preparation for some courses I'll be taking in January. There was a beautiful logic problem in Chapter 1, apparently created by Einstein. This is one version of it: Five men with  different nationalities and with different jobs live in  con secutive houses on a street. These houses are painted  dif ferent colors. The men have different pets and have   dif ferent favorite drinks.  Determine who owns a zebra and  whose favorite drink is mineral water (which is one of the  favorite drinks) given these clues:  The Englishman lives  in the red house.  The Spaniard owns a dog.  The Japanese  man is a painter.  The Italian drinks tea.  The Norwegian  lives in the first house on the left.  The green house is  immediately to the right of the white one. The photogra pher  breeds snails.  The diplomat lives in the yellow house. ...

Job as Entry Level Developer

After 4 months of work, sometimes focused, sometimes not, I accepted a job as an Entry Level Ruby on Rails Developer yesterday. This is after starting with zero knowledge on November 1, last year. Beyond knowing a little about coding (but getting the definitions of  REST and AJAX wrong), what were the reasons for the job offer?  I think it was the meetup group I started in January that made me stand out from the rest. The motivation for the meetup group was to help me become a better coder and to indulge my teacher instincts. After some initial meetings at the library and my home, an IT hub in town offered to host us. This meant extra advertising and prestige for the group. After announcing the meetup group at an Agile meetup group for developers, I got some volunteers to give talks. The first volunteer offered a talk on Ruby. As I was comfortable with Ruby I prepared a coding tutorial .  After the tutorial, which was attended by some beginners and some a...

Algorithm Analysis - 1

Currently, I'm learning to perform algorithm analysis using Big-O notation. In one resource I found the following problem: You just dropped a box of glass toys and  n  toys in the box broke in half. You'd like to match the halves of the toys so that you could glue them together, but the only way to tell whether two halves belonged to one toy is to physically pick up the two pieces and try to fit them together. Express how long this matching process will take in terms of  n . The answer given is n^2 (n squared) with the following explanation:  You have to compare every piece with every other piece. If you have 1 toy and it breaks in half, you have 1 comparison to make. If you have 2 toys and they both break in half there are 4 pieces and you have to do 6 comparisons. If you have 3 toys, there are 6 pieces and you have to do 15 comparisons. If you have  N/2  toys, you have  N  pieces and you have to do N-1 + N-2 + N-3 + ... + 1 =(N)(N-1)/2...