Make a java class called sequence

Assignment Help JAVA Programming
Reference no: EM132057206

Task 1. Make a Java class called Sequence which prompts the user for a single integer value called n, and reports the sequence of integers generated by the following rules, until1 the computed value becomes 1:

  • if n is even, the next value in the sequence is half of n if n is odd, the next value in the sequence is 3n+1

At the end of the program, the number of values in the sequence starting from the original n, and going to the value 1 should be reported, as shown below. If the user enters a value of n which is non-positive, then your program should simply output the message shown below in Sample 3 below and end.

Notes on spacing:

  • Each colon output by the program should be followed by a single space character.
  • Each value in the sequence output by your program should be followed by a single space,
  • including the final 1 value.
  • The Total number of values: line starts on a new line, and after the value is printed,
  • ends with a newline character.
  • The message The entered value was not positive., when needed, starts on a new
  • line, and ends with a newline character.
  • Here are three separate sample executions, with user input shown in bold:
  • SAMPLE 1
  • Please enter a positive starting value for n: 5 Sequence: 5 16 8 4 2 1
  • Total number of values: 6
  • SAMPLE 2
  • Please enter a positive starting value for n: 7 Sequence: 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 Total number of values: 17
  • SAMPLE 3
  • Please enter a positive starting value for n: -3 The entered value was not positive.

Reference no: EM132057206

Questions Cloud

Ninety-nine bottles of beer on the wall : Need a program that outputs the lyrics for "Ninety-nine Bottles of Beer on the Wall." Your program should print the number of bottles in English
What are 3 ways to improve a program : What are 3 ways to improve a program? These improvements should be related to the use of thread.
Containing integers sorted in ascending order : You are given a list, L , and a another list, P, containing integers sorted in ascending order.
Make a main method that will accomplish the following steps : Make a main method that will accomplish the following steps. (You may assume that the class includes all appropriate setter methods and getter methods)
Make a java class called sequence : Make a Java class called Sequence which prompts the user for a single integer value called n, and reports the sequence of integers generated by the following
Define a class named hotdogstand : You operate several hot dog stands distributed throughout town. Define a class named HotDogStand that has a member variable for the hot dog stand
Import the reviewquiz and review classes into eclipse : In the ReviewQuiz application, we created 2 Review objects. We wrote five statements to display the data in the first Review object
Prompt the user for two integers : Prompt the user for two integers, then accept the two integers from the user. Print a message that states whether or not the values are the same.
Make a method named comparevalues that determines : Make a method named compareValues that determines if two values are the same. The values are of type int. If the values are the same, return true; otherwise.

Reviews

Write a Review

JAVA Programming Questions & Answers

  What situation or problem is that you intend to improve

what you plan to accomplish and why, include an overview of situation or organization and what situation/problem is that you intend to improve - usually 1-2 pages) Cite and support all content appropriately.

  Create a java application that displays the product number

Create a product class that holds the item number, the name of the product, the numberof units in stock, and the price of each unit.

  Create a java gui application

Create a Java GUI application that allows the user to perform the tasks below on the books database. The user must be able to enter new data

  Define the class pictures

Implements draw() so that it draws some interesting picture. Each of these subclasses should have a constructor with a single Turtle parameter

  Sentence patterns and verb formulas

Provide the sentence pattern. Write out the sentence pattern - then write out the tense of the verb and provide the formula.

  Explain the inventory program to include an add button

Modify the Inventory Program to include an add button, a delete button, and a modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock

  Write a java program that declares an array alpha

Write a java program that declares an array alpha to 50 elements of type double. Initialize the array so that the first 25 numbers are equal to the square of the index variable, and the last 25 elements are equal to 3 times the index variable. Output..

  Develop and test html document that has checkboxes for apple

Develop and test an HTML Document that has checkboxes for apple (59 cents each), oranges (49 cents each), and Banana (39 cents each), along with a submit button.

  What violations and crimes would you definitely file

What if you were a parole officer and had to decide whether or not to file complaints against your parolees? What violations and crimes would you definitely file complaints for and what would you most likely overlook and why?

  Implementation of the finger protocol

Server programs are rarely implemented as non-threaded applications, even though that is how you implemented your previous server application.

  Determine the worst-case time complexity

Determine the worst-case time complexity of the following pseudocode algorithm. Assume that DoOtherStuff has a time complexity of O(n) where n = r-l

  Creates a coin table with coin names and values

Write a Java program that creates a Coin table with coin names and values; inserts  coin types penny, nickel, dime, quarter, half dollar, and dollar; and prints out the sum of the coin values. Use CREATE TABLE, INSERT, and SELECT SUM SQL commands.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd