The Signs Doing Homework

A Java Course Outline
Using the Java By Dissection book
by Ira Pohl and Charlie McDowell


Homework 5 - The Zodiac - What's your sign problem

We will write a program that will be a number of methods to compute the probability that two people at a party have the same sign. The program will also get us to use random numbers. There are 12 signs of the zodiac: listed below. For example, in a party of 12 or more people the probability that two people have the same sign is 1. We want to know this probability for n =2, 3, 4, 5, ..., 11.

We will compute the sign of each party goer using the expression . This yields a number between 0 and 11. Cast this expression to and you have the basis for a switch statement of the form:

switch( (int)(Math.random()*12)) { case 0: leo++; break; case 1: cancer++; break; //other cases and default if desired }

Initially each sign such as leo is an variable of value zero. If there are 5 people in the party we would compute using a loop the sign of each of the five people. The condition that more than 2 people in the room have the same sign should yield true if any sign variable such as . A method should be used to yield a boolean based on 1 trial. Then using 100 trials for each ( 2 to 11) would give you the estimated probabilities.

Write a method that outputs your results in a legible manner. It might print out:

For 100 trials of 2 people the probability of the same sign is 0.0831 For 100 trials of 5 people the probability of the same sign is 0.767. For 100 trials of 11 people the probability of the same sign is 0.967.

The Signs of the Zodiac

AriesMarch 21-April 19
Taurus April 20-May 2
Gemini May 21-June 20
Cancer June 21-July 22
Leo July 23- Aug. 22
Virgo Aug. 23-Sept. 22
Libra Sept. 23- Oct. 22
Scorpio Oct. 23- Nov. 21
Sagittarius Nov. 22-Dec. 21
Capricorn Dec. 22-Jan. 19
Aquarius Jan. 20-Feb 18
Pisces Feb. 19-March 20


Write out your methods in pseudocode. Make sure each method works independently of the entire program. Work out one case first, such as n = 5. After doing one case right it should be easy to write a loop that generates all 10 cases (n = 2, ne =11).

Leverage the work you have already done with Homework 4 to do this one. And his idea of getting a small piece of it working at a time is a really good one. Write and test a subset of the total program. When that is working, extend it to do the next thing... and so on until you have a good working program.

Some things to be sure to do to increase your grade
  • Give good variable names... (ie don't use for zodiac sign)
  • Give some thought to formatting your output... remember, you have to think about your user... how would you like it if the program you just launched just said "Type a number: " and then gave you some cryptic answer like "The probability is 0.895 Enter another number"
  • Make sure that your .java file compiles and runs correctly before you decide that you are done. As an example, say you finished up the program, and it compiles and works great. Now, to increase your possible points, you change your variable names and add a few comments. No need to recompile? Yes, you need to recompile, as the chances of getting it totally correct are astronmically small. Check every change. It could save your grade.

Today I was scrolling through my old photos and I found a screenshot of a text about the zodiac. And I thought it would be cool to post it here :joy: If you like it I will probably post more of this.

Btw It's just for fun so don't take it too seriously :joy: :joy:





You wish


Tries really hard to concentrate but gets distracted by the pretty music playing in the background


Looks at it for five minutes, puts it away


Watches 3 seasons of a TV show instead


Has better things to do


Actually does it


Says they will do it later but doesn't


Is too busy crying about the fact that they have to go to school tomorrow


Tries to do it and might actually succeed


Does it and brags about it later


Did not know they had homework


What is homework

0 thoughts on “The Signs Doing Homework”


Leave a Comment

Your email address will not be published. Required fields are marked *