Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Exercises

 

Exercise 1

Exercise 2

Exercise 3

Exercise 4a

Exercise 4b

Exercise 5

 

Exercise 1

 

Assume that you are the mananger of a restaurant. Establish a price for cokes, fries, and burgers and set a tax rate.

Write a program that will

§ Provide a greeting for a customer and announce the price of cokes, fries, and burgers.

§ Take the customer's order.

§ Announce the total bill, including tax.

 

Use separate methods to

§ Provide greeting

§ Announce prices

§ Take number of fries

§ Take number of cokes

§ Take number of burgers

§ Calculate and announce total price

 

Exercise 2

 

In the main method, prompt the user to enter an integer grade between 0 and 100.

Pass this grade to a method named conversion

 

The conversion method will use the following logic to convert the integer grade to a letter

grade, A, B, C, D, or F according to the following logic.

 

§ If the grade is greater than or equal to 90 and less than or equal to 100 then letter grade = A

§ If the grade is greater than or equal to 80 and less than 90 then letter grade = B

§ If the grade is greater than or equal to 70 and less than 80 then letter grade = C

§ If the grade is greater than or equal to 60 and less than 70 then letter grade = D

§ If the grade is less than 60 then letter grade = F

 

When the letter grade is returned to the main method, the main method will pass it to a method named

printIt.  The method named printIt will print the numeric grade and its equivalent letter grade

 

Exercise 3

Lucky 7: Version 1 (non-visual)

 

Required part (note: all of the code can be in the main method for this exercise)

 

§ Use the random number generator to create 3 random numbers, each of which is in the range 1 to 10 (including 1 and 10

§ Assign these number to appropriately named variables

§ If no sevens are obtained, print an appropriate message

§ If 1 seven is obtained, print an appropriate message

§ If 2 sevens are obtained, print an appropriate message

§ If 3 sevens are obtained, print an appropriate message

 

 

Exercise 4a (non-visual version)

 

§ Assume that you have a square such that its 4 sides are tangent to a circle drawn inside the square.

§ Throw randomly generated darts such that they all fall within the square

§ Use this approach to approximate the value of pi

§ Your output should contain the dimensions of the square and circle, the total number of throws, and the value of pi obtained

 

Exercise 4b (Visual Version)

 

§ Draw a vertical and a horizontal axis - they do not have to be labeled

§ Use an appropriate caption for the form (appears at upper left corner - form1 by default)

§ Place an appropriate title at the top and approximate center of the form (Calculating Pi, for example) - do this using the drawString method. Do not use a

      TextBox

§ Draw a square such that its bottom left vertex is at the origin of the above coordinate system

§ For the above square, draw an inscribed circle (given a pollygon, a circle is considered "inscribed" if it is tangent to each side of the polygon)

§ Throw randomly generated darts such that they all fall within the square - draw the impact point as they are thrown

§ Use this approach to find the value of pi

§ Your output should contain the square, the circle, length of a side of the square, the total number of throws, and the value of pi obtained.

§ Additional requirements

     Ø Give the user 2 choices of background color for the form using RadioButtons

     Ø Give the user 2 choices of foreground color for the form using RadioButtons

     Ø The value of pi calculated, the number of throws, and the side of the square should be placed in a text box.

 

 

Exercise 5

 

Lucky 7: Version 2 - Visual

This lab uses the Windows Application version of VB

 

Part 1

 

§ Use the random number generator to create 3 random numbers, each of which is in the range 1 to 10 (including 1 and 10

§ Assign these number to appropriately named variables - then to a TextBox

§ If no sevens are obtained, print an appropriate message in a TextBox and show an appropriate Picture in a PictureBox

§ If 1 seven is obtained, print an appropriate message in a TextBox and show an appropriate Picture in a PictureBox

§ If 2 sevens are obtained, print an appropriate message in a TextBox and show an appropriate Picture in a PictureBox

§ If 3 sevens are obtained, print an appropriate message in a TextBox and show an appropriate Picture in a PictureBox

 

Part 2