programming, computer science homework help

  

exam1.docx

Unformatted Attachment Preview

Don't use plagiarized sources. Get Your Custom Essay on
programming, computer science homework help
Just from $10/Page
Order Essay

1. Find the Errors: The following code contains many errors. The errors may be
syntax, logic, or violations of conventions discussed in class. Copy this code into DrJava
and make any necessary corrections to the code so that it compiles and produces the
required output when run. Also, make sure that all naming conventions are followed.
Copy your corrected code from DrJava into the appropriate space in Blackboard.
// Class demonstrates the error of using a random range
//
of (2 – 12) to simulate a 2-dice roll
public class simulateDiceRolls {
public static void main(String[] args) {
Random rand;
int roll1, roll2, sum, singleDice7s = 0, pairDice7s = 0;
System.println(“Simulating 10,000 rolls
of the dice”);
for (int i = 0; i < 10000;) { // roll the dice 10,000 times roll1 = rand.nextInt(6) + 1; // Simulate rolling 2 dice roll2 = rand.nextInt(6) + 1; sum = roll1 + roll2
if (sum = 7) {
// Count the number of 7s
singleDice7s++;
}
roll3 = rand.nextInt( ) + 2;
// Simulate using 1 roll (2 12)
if (roll3 == 7) {
// Count the number of 7s
pairDice7s+;
}
}
// Show % of 7s for each simulation using:
(count/10,000) * 100)
System.out.println(% 1 roll = ” +
doublesingleDice7s/100);
//16.67%
System.out.printf(“% 2 dice = %dn” , (double)pairDice7s/100); //
9.09%
}
}
2. Programming
Write a complete program that compares the number of vowels in names entered by a
user. Your program should first ask the user for the number of names to be entered, and
then repeatedly asks the user to enter names until that number is reached.
Each name entry will be of the form:
Your program should include a method named countVowels that receives a single String
parameter and returns the number of vowels found in that String.
When finished, the program should output the name with the most vowels and the
number of vowels in that name. If two names have this same maximum number of
vowels, only the first name entered will be displayed.
3.
Programming
Write a complete program that plays a single game of craps, displays the individual rolls
and reports when a game is “LOST” or “WON” and shows the number of rolls used by
the game.
The algorithm is as follows:
 Simulate the roll of 2 dice using a JAVA random number generator.
 Record the sum of this first roll as the game point and print out: Game point:

 (if) the game point is 7 or 11
print out: Game won in 1 roll
 (else) continue rolling the dice. After each roll, print:

a. (if) a roll is either 7 or 11
print out: Game lost in rolls. Sorry.
b. (else if) a roll equal the game point
print out: Game won in rolls. Congratulations!
c. Otherwise, repeat step 4
4.
Programming
Write a static method named favoriteLetter that accepts two parameters: a Scanner from
the console, and a favorite letter represented as a one-letter String. The method
repeatedly prompts the user until two consecutive words are entered that start with that
letter. The method then prints a message showing the last word typed.
You may assume that the user will type single-word responses to each prompt. Your code
should be case-sensitive, (if the favorite letter is a, you should not stop prompting if the
user types words that start with a capital A.
The following represents output from two calls to your method:
(User input is underlined.)
Scanner console = new
Scanner console
Call
Scanner(System.in);
favoriteLetter(console, “y”);
Output Looking for two “y” words
in a row.
Type a word: hi
Type a word: bye
Type a word: yes
Type a word: what?
Type a word: yellow
Type a word: yippee
“y” is for “yippee”
5.
= new
Scanner(System.in);
favoriteLetter(console, “A”);
Looking for two “A” words
in a row.
Type a word: I
Type a word: love
Type a word: COSC236!
Type a word: AND
Type a word: PROGRAMS
Type a word: are
Type a word: always
Type a word: Absolutely
Type a word: Awesome
“A” is for “Awesome
Programming
Write a static method named countEvenDigits that accepts an integer as its parameter
and returns the number of even-valued digits in that number. An even-valued digit is
either 0, 2, 4, 6, or 8.
For example, the number 8546587 has four even digits (the two 8s, the 4, and the 6), so
the call countEvenDigits(8346387) should return 4.
You may assume that the value passed to your method is non-negative. You may
NOT use a String to solve this problem.

Purchase answer to see full
attachment

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more

Order your essay today and save 30% with the discount code ESSAYSHELP