Java Programming Assignment: Integer Input and Array Handling in Java

Verified

Added on  2023/04/25

|8
|937
|481
Homework Assignment
AI Summary
This Java programming assignment focuses on developing a program that takes comma-separated integer inputs from the user. The solution utilizes the Scanner class to handle user input, with the useDelimiter() method to separate the inputs based on commas. The program then stores these integer inputs into an array. Exception handling, using try-catch blocks, is implemented to manage potential errors during input or processing. The program's structure includes a getinput() method to handle input, a main method to call the getinput() method and display the output. The assignment also includes a reflection section, discussing the program's purpose (storing and displaying comma-separated values), the algorithm used (Scanner and arrays), input and output formats, limitations (array's use of continuous memory), and error handling. The program demonstrates fundamental OOPS principles, memory management, and is checked against the program specifications. The assignment is designed to provide students with practical experience in Java programming, data input, array manipulation, and exception handling.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Running head: JAVA PROGRAMMING ASSIGNMENT
Java Programming Assignment
Name of the Student
Name of the University
Authors note
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
1JAVA PROGRAMMING ASSIGNMENT
Introduction
The program is developed in order to get input from the users as integers. In order
to take the input a separate method is declared and is called from the main method in the
program accompanied java program. The program also included the use of exception
handling using the try catch block. The integer inputs provided by the users is separated by
the comma and is displayed after calling the method from the main method.
Pseudocode
Declare getinput () method
Declare object of a scanner class
Declare “useDelimiter("\\D")” for specific delimiter in the program in order to take
comma separated input.
Declare int array[]
Initiate try catch block
For int i=0 to length of the array.
Assign values to the array
End of for loop
End of method
Start main
Call getinput ()
End of main
Document Page
2JAVA PROGRAMMING ASSIGNMENT
Completed Program
package javaapplication;
import java.util.Scanner;
public class JavaApplication {
public static void getinput()
{
Scanner inp=new Scanner(System.in);
//Declaring object of scanner class
inp.useDelimiter("\\D");
int array[] = new int[3];
try {
for(int i=0;i<array.length;i++)
{
array[i]=inp.nextInt();
}
// j=inp.nextInt();
Document Page
3JAVA PROGRAMMING ASSIGNMENT
// k=inp.nextInt();f
for(int j=0;j<array.length;j++){
//declared array of integer
System.out.print("\t"+array[j]);
}
inp.close();
}
catch (Exception e) {
System.out.println("Some thing went wrong");
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here]
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
4JAVA PROGRAMMING ASSIGNMENT
// Scanner sc = new Scanner(System.in).useDelimiter(",");
// Scanner sc = new Scanner(input).useDelimiter(",");
//
System.out.println("Please enter three integers separetd by comma");
getinput();
}
}
Reflection Question
Purpose of the program: The java program is designed to take comma separated
user input and store them in an array as well as printing them at the end of the execution of
the program.
Algorithm used in the program: In order to take the input from the user, the
Scanner class and its objects are used. After this the integer arrays are then used to store the
values using the for loop.
Program input: Comma separated three integers values are input for this
program which can be increased and decreased by modifying the value in the for loop.
Program output: The comma separated values from the array are the output of this
program.
Limitations: The Program uses array data structure thus uses continuous memory spaces
which is a draw back in standard OOPS programing paradigm.
Document Page
5JAVA PROGRAMMING ASSIGNMENT
Errors: Usually there is no error in the program if any error occurs in the execution that
managed using the Try catch block in the program.
Program structure and logical implementation
In order to complete the program at first the getinput () method is declared in the
class. Now in this method, a integer array is declared in which the user inputs will be stored
and retrieved in order to show that as output. In order manage any of the storage or data
related error while executing the program the try catch block is used. In order to take the
input of integers as comma delimited input, the usedelimiter () method is utilized. This
method along with the scanner object is used to get the inputs from the user. The provided
delimiter helps the scanner object to tokenize string. This method is helpful in this scenario as
the program intend to use Scanner to split the user provided string in multiple tokens.
Document Page
6JAVA PROGRAMMING ASSIGNMENT
Conclusion
The program is developed using the OOPS paradigm is helpful in managing the
memory utilization for storing and displaying at the end of the execution. Output of the
developed program is checked against the specified format as mentioned in the program
specification.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7JAVA PROGRAMMING ASSIGNMENT
Bibliography
Cooper, J. W. (2017). Design Pattarn Java Companion. Addison Wesley.
Mehrabi, M., Giacaman, N., & Sinnen, O. (2018, May). Unobtrusive Asynchronous
Exception Handling with Standard Java Try/Catch Blocks. In 2018 IEEE
International Parallel and Distributed Processing Symposium (IPDPS) (pp. 855-864).
IEEE.
Ogihara, M. (2018). Generic Class Parameters and the Java Collection Framework.
In Fundamentals of Java Programming(pp. 457-484). Springer, Cham.
Olsson, M. (2018). Java quick syntax reference. Apress.
Purohit, P., & Tokekar, V. (2018). An Investigation of Exception Handling Practices in .NET
and Java Environments. International Journal of Applied Engineering
Research, 13(5), 2130-2140.
chevron_up_icon
1 out of 8
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]