Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercises 1. Counting ones : [20 marks] We would like to have a program to count the number of ones in the binary representation of
Exercises 1. Counting ones : [20 marks] We would like to have a program to count the number of ones in the binary representation of a given integer by user. The program must take an integer (in base ten) between 0 and 99 from the user. (Do not worry about dealing with nonnumber inputs.) The program must display the number of '1's in the binary representation of the number entered by the user. For example, if the input is 14, the number of 1's is 3 since the binary representation of 14 is 1110. A. [10 marks] Let us create the blueprint. Answer the following questions: Input: What are the inputs? (name, type, source), Do we need any user input? If so, what should we prompt for? Output: What information are the outputs? (name, type, source) Calculations: What kinds of calculations might we need to do? Should we look up relevant formulas? What operators will we need to use? Variables: What variables will we need? What types should they be? Constants: Do we need any constants? If so, what type(s)'? B. [6 marks] Design an algorithm for the above program and represent it by a flowchart. C. [4 marks] Test your algorithm with different numbers such as 5, 14, 100, 0. To submit your answers for this question, use a file named answers.pdf. 2. Palindrome numbers: [12 marks] A number is palindrome if it reads the same from right to left and from left to right. For example, 121 is a palindrome but 443 is not. We would like to have program that generates a 3digits random integer number and determines whether it is a palindrome number. A. [5 marks] Design an algorithm to solve the problem, use pseudocode to represent your algorithm? (answers.pdf) B. [2 marks] Test your algorithm with 2 random number where one is palindrome and the other one is not. (answers.pdf) C. [5 marks] Write a java program for your algorithm named Palindrome.java. Here are 2 sample runs of this program: 121 is a palindrome. 443 is not a palindrome. 3. Card Game: [10 marks] Write a java program named CardGame.java that simulates 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. Here is a sample run ofthe program: The card has been picked is Jack of Hearts. Hint: your program needs to generate a random number between 1 to 52 and decides about the rank and suit of card based on the value of random number. You can also use two switch statements. 4. Guessing Game:[10 marks] Write a java program names GuessingGame.java that generates a random integer number between 1 and 10. Then it prompts user to enter a guess (\"What is your guess?\"). First it verifies if the guess is between 1 and 10, If it isn't then prints a message \"Well, if you're not going to \"try\
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started