1. Counting ones: [20 marks] We would like to have a program to count the number...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 non-number 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 3-digits 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 of the 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", I'm not playing". Otherwise, it checks whether user has guessed the number correctly. If so, it prints "Hurray. You win!". Otherwise, it displays the random number, and then it determines if the number was close. Close means within three numbers before and after random number. It then prints the message "You missed it by the miles" Or "It was close" depends on the result. Finally, the program wishes the user good luck by "Better luck next time." Here is the sample run: What is your guess? 2 The number was 10. You missed it by the miles Better luck next time Note: You are not supposed to handle non-integer guesses. Grading The programming questions are marked based on correctness, style of program and documentations. Add the external documentations in answers.pdf. 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 non-number 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 3-digits 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 of the 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", I'm not playing". Otherwise, it checks whether user has guessed the number correctly. If so, it prints "Hurray. You win!". Otherwise, it displays the random number, and then it determines if the number was close. Close means within three numbers before and after random number. It then prints the message "You missed it by the miles" Or "It was close" depends on the result. Finally, the program wishes the user good luck by "Better luck next time." Here is the sample run: What is your guess? 2 The number was 10. You missed it by the miles Better luck next time Note: You are not supposed to handle non-integer guesses. Grading The programming questions are marked based on correctness, style of program and documentations. Add the external documentations in answers.pdf.
Expert Answer:
Related Book For
Computer Architecture Fundamentals And Principles Of Computer Design
ISBN: 9781032097336
2nd Edition
Authors: Joseph D. Dumas II
Posted Date:
Students also viewed these programming questions
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
John Hasty opened his bakery on March 1, 1999. The following transactions took place in early March: 1. Deposited $10,000 into a checking account in the name of the Hasty Bakery. 2. Leased a small...
-
Prove that a diagonal matrix D = diag(d1,... , dn) is invertible if and only if all its diagonal entries are nonzero, in which case D-l = diag(1/d1..........1/dn) .
-
A chemical constituent flows between three reactors as depicted in Fig. P11.15. Steady-state mass balances can be written for a substance that reacts with first-order kinetics. For example, the mass...
-
Rockstar Games, a subsidiary of Take-Two Interactive, released the video game Grand Theft Auto V in 2013. The game features a character named Lacey Jonas, a self-proclaimed actress slash singer and...
-
Luxman Company has several processing departments. Costs charged to the Assembly Department for October 2012 totaled $1,298,400 as follows. Production records show that 25,000 units were in beginning...
-
The force exerted by a 2.4-m massless string on a 0.84-kg object being swung in a horizontal circle is 4.2 N. What is the tangential velocity of the object?
-
Required: Record the journal entry for the following transaction: Moon and Sky need money to buy equipment to win a contract. They offer Starz a 35% share for a $100,000 investment The partnership...
-
What are the typical effectiveness goals of the purchasing process? Provide an example illustrating each goal.
-
What is the payroll process? What functions and activities does the process perform?
-
Subway now requires all of its franchisees to submit their weekly sales and inventory reports electronically using new point-of-sale (POS) touch-screen cash registers. With the new POS registers,...
-
Describe an employee self-service system.
-
Go to the 2010 annual report for Kelloggs Company at http://investor.kelloggs.com/annuals.cfm and find the Consolidated Balance Sheet. Calculate for Kelloggs the current ratio for 2009 and 2010.
-
Discuss the situations that make it more likely for children and the elderly to become victims of crime and how vulnerabilities as a result of age or ability level contribute to victimization....
-
At Glass Company, materials are added at the beginning of the process and conversion costs are added uniformly. Work in process, beginning: Number of units Transferred - in costs Direct materials...
-
In a steam power plant, coal is burned at the rate of 50 lbm/min. The percentage of ash in the coal is 9% by mass. The combustion of coal takes place in a fluidized bed reactor and the ash in the...
-
2-Mercaptoethanol (C 2 H 6 OS) is produced by reacting ethylene oxide (C 2 H 4 O) with hydrogen sulfide (H 2 S) as per the following reaction equation. The reaction takes place in the presence of...
-
Chlorobenzene is produced by direct chlorination of benzene. However, a parallel reaction that produces dichlorobenzene hexachloride also occurs. The parallel reactions are shown here. The single...
Study smarter with the SolutionInn App