JAVA only. Do not copy and paste from another code, you will not get points. Wri
ID: 3540892 • Letter: J
Question
JAVA only. Do not copy and paste from another code, you will not get points.
Write a program that reads in an integer that is greater than 1,000 and less than 1,000,000. Recall that the number must be entered without any commas. Display the number with a comma inserted where it belongs. (Hint: use the % operator).
Use the Analysis and Design template included to design your program.
Write the program in java, using properly formatted javadoc comments to generate the specification. Use the throws statement to throw exceptions as needed.
_________________________________________________________________
after code please do sections
1. Introduction:
Method Name:
Complete Heading:
Description:
2. Parameter List:
Parameter name - Parameter description
Parameter name - Parameter description
(Continue the list for each additional parameter)
3. Precondition(s):
(List of conditions that are supposed to be true when a method is called)
4. Returns Condition or Postcondition:
(What will be true when the method is completed)
General guidelines:
4.1. Use a Returns Condition if the method returns a value
4.2. Use a Postcondition for void methods or methods that use reference parameters instead of or in addition to returning a single value
5. The Throws List:
Describe the checks that will be made inside the method to ensure that the precondition is met (see Appendix C for the names and descriptions of the exceptions that can be thrown in Java) .
Exception name - describe the condition that will cause this exception to be thrown.
(See the Programming Tip on page 9 in your textbook for guidance)
(The following sections do not need to be included in your code)
List any formulas your method will use (leave this section out if your method does not use formulas).
Algorithm:
Decompose your method into subtasks. Present your algorithm as a list or as pseudocode; do not put code in this document.
Put the name of the lower level method if the subtask will be decomposed further.
Your main method should be the most abstract (i.e., most of the steps are subtasks).
Your lowest level methods should be cohesive (i.e., performs only one operation or task).
Test Plan:
Explanation / Answer
import java.util.*;
public class numberformatter
{
// Method Name: print_with_commas
// Complete Heading: public static void print_with_commas(int num)
// Description: This method prints input number with commas in appropriate place.
// Parameter List:
// Parameter name - Parameter description
// num its of type integer
// Precondition(s): valid input argument i.e integer
// Postcondition : None . Number will be printed with appropriate commas.
public static void print_with_commas(int num) throws Exception
{
if(num<1000 || num > 1000000)
throw new Exception("Number is out of range");
System.out.println(num/1000 + "," + (num%1000));
}
public static void main(String[] args)
{
int number = 0;
Scanner in = new Scanner(System.in);
System.out.println("Enter your number :");
String input = in.nextLine();
try
{
number = Integer.parseInt (input);
}
catch (NumberFormatException e)
{
System.out.println("Input data is not proper integer :" + e);
System.exit(0);
}
try
{
print_with_commas(number);
}
catch(Exception e)
{
System.out.println("Exception Occured: " + e.getMessage());
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.