Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
 CS 1301 
Lab 4 
 
Working with Selections and Mathematical Functions – Chapter 3 & Chapter 4 
 
 
For each lab program you develop during this course, make sure that include the following header - replace the 
dots in the header with your section #, semester, your full name, your instructor’s name, and lab #: 
 
// Class: CS 1301/12 
// Term: ... 
// Name: ... 
// Instructor: ... 
// Lab#: ... 
 
Exercise #1: Write a Java program (name it Practice_4_1) that simulates (randomly) picking a card from a 
deck of 52 cards. Your program should display the rank (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, 
Queen, King) and suit (Clubs, Diamonds, Hearts, Spades) of the card. Use switch statement at 
least once. Label your output properly. 
 
The card you picked is Jack of Hearts  
The card you picked is 2 of Diamond 
 
Exercise #2: Write a Java program (name it Practice_4_2) that randomly generates three single-digit numbers 
and prompts the user to enter the sum of these three numbers. Print out the entered answer followed by the 
message “Correct!“ if the answer is correct, or the message “Incorrect! The correct answer is XXX.” 
if the entered answer is incorrect. Use the following sample outputs to format your outputs. 
 
What is the sum 9 + 3 + 7?  
You entered 19  
Correct!  
What is the sum 9 + 3 + 7?  
You entered 15  
Incorrect! The correct answer is 19 
 
 
Exercise #3: Write a Java program (name it Practice_4_3) to prompt the user to enter a point (x, y) and 
checks whether the point is within the circle centered at (0, 0) with radius 10. 
 
Hint) The formula for computing the distance is √(𝑥2 −  𝑥1)2 + (𝑦2 − 𝑦1)2 
 
 
Enter a point with two coordinates: 4 5 
Point(4.0, 5.0) is in the circle 
 
 
 
Instructions: 
 
1. Programs must be working correctly. 
2. Programs must be completed and checked by TA before submitting to D2L. 
3. Programs must be checked during the designated lab session.