Java programming

profileDevaraj_555
assign3.pdf

CIS 265 Data Structures and Algorithms

Assignment 3

Due: 12:24pm, Tue, Feb. 16, 2021

100 points

I. Description

In this assignment, you will add input checking in the program in assignment 2. A valid student ID should

be an integer between 1000000 and 9999999. A valid student GPA should be a double between 0 and 4.0.

No other function is added to the program in assignment 2.

1. The program will first ask the user to input the number of students to be created. If the user inputs a value in wrong format, such as a double or string, the program should print an error

message “Please input a number between 1 and 10.” The number should be from 1 to 10.

Otherwise, the program prints “I cannot create xxx students!” where xxx is the input number.

If the input is in wrong format or outside the range, the program should ignore the input and

prompt again.

2. When the program prompts the user for student ID, if the user input a value in wrong format or an invalid value, it will print an error message “Please input an integer between 1000000

and 9999999.”, ignore the input, and prompt again.

3. When the program prompts the user for student GPA, if the user input a value in wrong format or an invalid value, it will print an error message “Please input a valid GPA (0-4.0)”,

ignore the input, and prompt again.

4. After the input of the Student objects, the program will then search the student array. It keeps asking the user for a student ID. If the user inputs 0, the program will print “Goodbye!” and

exit. If the user does not input an integer, the program should print an error message, “Please

input an integer between 1000000 and 9999999”. If the user inputs an integer but an invalid

ID, the program will a message, “A valid ID is an integer between 1000000 and 9999999”. In

both cases, the program will ignore the input and prompt the user again.

5. If the user inputs a valid ID, the program will search the student array for the given student ID. If a match is found, the program will call printStudent() to print the student information.

If no match is found, the program prints “Student ID xxxx not found.” where xxxx is the ID

given by the user.

6. Since the student array may not be sorted, you should use linear search. 7. A sample run will look like this where the green texts are user inputs:

How many students do you have(1-10): two Please input a number between 1 and 10. How many students do you have(1-10): 0 I cannot create 0 students! How many students do you have(1-10): 11 I cannot create 11 students! How many students do you have(1-10): 2 Student 1 name:Si Ti Student 1 ID:oneone Please input an integer between 1000000 and 9999999

Student 1 ID:2021 Please input an integer between 1000000 and 9999999 Student 1 ID:999999 Please input an integer between 1000000 and 9999999 Student 1 ID:10000000 Please input an integer between 1000000 and 9999999 Student 1 ID:1000000 Student 1 GPA:good Please input a valid GPA (0-4.0) Student 1 GPA:4.11 Please input a valid GPA (0-4.0) Student 1 GPA:-0.0000001 Please input a valid GPA (0-4.0) Student 1 GPA:2 Student 2 name:Sa Li Student 2 ID:9999999 Student 2 GPA:4 Enter a valid student ID (enter 0 to quit): not sure Please input an integer between 1000000 and 9999999 Enter a valid student ID (enter 0 to quit): 1000 A valid ID is an integer between 1000000 and 9999999 Enter a valid student ID (enter 0 to quit): 1000000 Student name:Si Ti Student ID:1000000 Student GPA:2.0 Enter a valid student ID (enter 0 to quit): 9999999 Student name:Sa Li Student ID:9999999 Student GPA:4.0 Enter a valid student ID (enter 0 to quit): 0 Goodbye.

II. General Requirements

• Your program must include two Java files, one for the main class and the other for the Student class. You may reuse the Student class from Assignment 2.

• Both classes must be in the same package. The package name should start with your last name, e.g., FuCIS265.

• Please name your main class file under your last name. For example, if your last name is “Fu”, your file name should start with “Fu”, e.g., FuAssignment3.java.

• The Scanner’s nextInt() or nextDouble() method does NOT read the newline character. You need to call a nextLine() after nextInt() or nextDouble() to discard the newline character.

• It is essential that you use nextLine() to discard the wrong input in the catch statement. Otherwise, your program may go to infinite loop.

• I suggest you break the input processing into multiple methods.

III. Submission

This is an individual assignment. Each student needs to submit the source code files of the Java

program on Blackboard.

1. You must submit a zip file of the package, i.e., the folder with your source files.

2. You need to submit only the source code, i.e., the Java files. 3. You may submit multiple time. Your most recent submission before the deadline will be

graded.

IV. Grading 1. A program that does not run will receive 0 point. 2. There is a 10-20 points deduction for each major error, e.g., do not find a student. 3. There is a 1-9 points deduction for each minor error, e.g., a spelling error in printed message. 4. A program that does not follow the guidelines will lose 1-10 points. 5. Any type of cheating is not tolerated. You may be asked to explain your program in person.