two code about the introduction of java

  • 1
  • Create a new Java file Valentine.java.
  • Write a program that uses a while loop to print the numbers from 1 to 150, with each number printed on its own line.
  • For multiples of 3, print “Roses are red.” instead of the number.
  • For the multiples of 5, print “Violets are blue.” instead of the number.
  • For numbers which are multiples of both 3 and 5, print “Sugar is sweet, and so are you!”.
  • You must use a while loop for full credit.
  • Hint: Test for numbers that are multiples of both 3 and 5 first.

2.

  • The New Hampshire Primary is taking place this Tuesday, February 11, 2020.
  • According to Wikipedia, a primary “Primary elections or often just primaries, are the process by which voters can indicate their preference for their party’s candidate, or a candidate in general, in an upcoming general election… with the goal of narrowing the field of candidates”
  • The New Hampshire primary is the first of the primary elections, which will be held to select the Democratic nominee for the 2020 presidential race.
    • Note that the Republican nominee has essentially already been determined
  • Although New Hampshire is just a small state, its primary receives massive media coverage, and, therefore, has a greater influence over the Democratic race than is small size would suggest.
  • In this assignment we will develop a program to count votes for the 2020 New Hampshire Primary.
  • The user enters votes based on a simple menu that presents the candidates.
  • The user then inputs a single character (upper or lowercase A-C) to choose their candidate from the menu.
  • Entering an ‘X’ (without the quotes) will exit the tallying operation and present a summary of the votes.
  • Write your code inside the file Primary.java.
  • Present a list of candidates to the user and allow her to enter a single character as input, and no other input, as shown in the Example Output.
  • Use an indefinite while loop to allow multiple votes to be cast on your voting machine.
  • After all the votes are entered and the user enters an ‘X’, exit the loop and report the vote count by candidate names and neatly aligned as shown in the Example Run.
  • Your program should also report an error message if the user enters a letter other than A-C or X, as shown below.