Instructions 1. Use JGRASP to write, compile error free and run all code error free. (10 points) 2. Upload the compiled, error-free file as exam2_<yourlastname>.java to Blackboard by 9:50pm. (5 points) 3. Be sure to use proper programming techniques such as line spacing, indentation and comments before each section describing each section. (10 points) 4. Create a Java program which includes the following: a) Ask the user to enter a number between 10 and 90. (5 points) b) Check to make sure they enter a number between 10 and 90. If the number is not between 10 and 90, ask the user to reenter a number between 10 and 90. (15 points) c) Create and call a method to print a line for each number starting with the current number counting down to 0. (15 points) 5. Ensure your output matches the sample output below. (10 points) Sample Output: Enter a number between 10 and 90: 9 Please enter a number between 10 and 90: 91 Please enter a number between 10 and 90: 15 The current number is 15 The current number is 14 The current number is 13 The current number is 12 The current number is 11 The current number is 10 The current number is 9 The current number is 8 The current number is 7 The current number is 6 The current number is 5 The current number is 4 The current number is 3 The current number is 2 The current number is 1 The current number is 0
Added by F-Tima R.
Close
Step 1
java. Next, you need to write a Java program that does the following: Show moreā¦
Show all steps
Your feedback will help us improve your experience
Akash M and 81 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Java Programming: Base Conversions Write a program that performs the following tasks: 1. Display a friendly greeting to the user. 2. Prompt the user for the value to convert (a String). 3. Accept that String. 4. Prompt the user for the value of the initial base (an integer). 5. Accept that integer. 6. Prompt the user for the desired base of the output (an integer). 7. Accept that integer. 8. If the String is not a legal expression of a number in the initial base, display an error message and exit the program. 9. Convert the value represented by the String in the initial base to the desired base. 10. Display the result. The program should also accept all three parameters from the command line if provided. Command-line parameters are accepted in the same order as the input prompts. For example: C:> java BaseConversions ABCDE 25 8 This will convert the input string ABCDE from base 25 into base 8 and display the result. Any base from 2 to 36 is accepted. Base 36 uses the integers 0-9 and the twenty-six letters A-Z / a-z. The validator and the actual conversion routine should be contained in functions: public static boolean isValidInteger(String theValue, int theBase) { // contract: returns true if theValue is a valid expression in theBase; false otherwise. } public static String convertInteger(String theValue, int initialBase, int finalBase) { // contract: converts theValue from initialBase to finalBase and returns the result as a String. // precondition: theValue must be a valid expression in initialBase. } You will need to use the Java BigInteger class, which allows arbitrary-length integers. You may not use the built-in base conversion functions in Integer or BigInteger. The only operations allowed are add, subtract, multiply, divide, and mod. Your conversion algorithm is as follows: 1. Check the validity of the input String. 2. Convert the input String from the initial base into a BigInteger (in base 10). 3. Convert that base-10 BigInteger into a String representation of that value in the desired target base.
Supreeta N.
In this assignment, you will use a loop and a custom method (called a "function"), as well as built-in Java classes. Create a Java program that meets the following requirements: Ask the user to input a number between 5 and 45, and tell the user to enter 1 if they wish to exit the program. Store the user's input in a variable with the integer data type. Use a while loop to repeat the program, checking the user's entry in case they entered a 1 to exit the program. A separate method called "checkEntry" has been created for you in the starting template below (note: You can restore the default code if you wish to start over by clicking the "Load default templateĆ¢ā¬Ā¦" link). In this method, take the user's entered number and process it such that IF the user enters a value of less than 35, the checkEntry method must multiply that value by 5 and return the result to main(). If the user instead enters a value greater than or equal to 35, the program must add 10 to that value and return the result to main(). Display the result of checkEntry's evaluation on the screen. Sample Values for Testing (paste into the "Enter program input (optional)" box below): 22 37 1 Important Notes (READ CAREFULLY!): When working correctly, this program will throw errors if you do not put a 1 at the bottom of the input sequence, as shown above. It is normal for this completed program to evaluate the exit condition (1), multiplying it by 5 and displaying the success message before terminating. This is the expected behavior for this assignment. This program does not check to see if the user failed to enter the right type of data. That topic will be examined later in this course. LabProgram.Java import java.util.Scanner; public class LabProgram { public static void main(String[] args) { // Type your code below this line. create additional lines as needed. // do not delete this line } public static int checkEntry(int incoming) { // Type your code for the checkentry method below this line. create additional lines as needed. // do not delete this line } }
Akash M.
Using printf only, create a Java program named: your last name + first letter of your first name + ubuntuPgm1.java In the above program, from the main method call a new method named: processUbuntu passing your name, the number 2021.99, and the word Fall 1) Using System.out.printf in a separate line, display the name of the editor you are using to write your program. 2) Using System.out.printf in a separate line, display the command to save and continue writing your program. 3) Using System.out.printf in a separate line, display the command to exit your editor without saving your program. 4) In the processUbuntu method, using System.out.printf, display the accepted data in three rows. - On the first row, display the first data field. - On the second row, display the second accepted data field, using 10 spaces for the integer part and 5 spaces for the decimal part of the number. - On the third row, display the third field accepted in CAPITAL LETTERS ONLY.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD