Question

USING JAVA Assume that you are the in-charge of maintaining student profile for the department of...

USING JAVA

Assume that you are the in-charge of maintaining student profile for the department of ILT.

You want to obtain the following details from the students.

1. First Name

2. Last Name

3. PeopleSoft Id (Don’t use original)

4. Class standing

5. Email id

6. Address

a. Address line 1

b. City

c. State

d. Zipcode When obtaining the above details, you need to validate each data as follows.

i. First name and last name should not contain any character other than alphabets [az/A-Z]

ii. PeopleSoft id should contain only digits and its length should be <=7.

v. The address line 1 should contain a house number followed by a space and a street name

vi. City name should consist of only alphabets vii. State should be any one of the states in US. AK, AL, AR, AZ, CA, CO, CT, DC, DE, FL, GA, HI, IA, ID, IL, IN, KS, KY, LA, MA, MD, ME, MI, MN, MO, MS, MT, NC, ND, NE, NH, NJ, NM, NV, NY, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VA, VT, WA, WI, WV, WY

viii. Zip code should be of length 9 and contain only numbers Your code should perform the following:

A. First, the application should ask how many students’ data (“N”) are to be entered.

B. Then initialize an array of objects to that number

C. Define a Class named Student with the student details from 1. – 6. As fields.

D. The Student Class should have a method “getInfo” to obtain the student details. When reading each input, you should validate the data as described from i. – viii.

E. The Student class should have a method “displayInfo” to display the student details. Each student data needs to be printed in a separated line with each data separated by a space (use “\t”).

F. The Student class should have a static member “count” to count the number of students.

G. While printing, the display should have a header line as “Students Details, Department of ILT”.

H. At the bottom of the display, it should print “Number of students: count”, where count should be equal to N.

Homework Answers

Answer #1

//completed.. Thanks

//------------ StudentTest.java

//package project123;

import java.util.Scanner;

class Student {
static int count;
String FirstName;
String LastName;
String PeopleSoftId;
String ClassStanding;
String EmailId;
String Address;
  
public Student() {
Address=""; // address is initially blank
count++; // increase count by 1 when new object is created
}   

public void setFirstName() {
Scanner sc = new Scanner(System.in); // to get input from user
loop1: while(true) { // loop1: is label for while loop
System.out.print("please enter First Name: ");
FirstName = sc.nextLine();
// check Firstname, and repeat if invalid
for (int i = 0; i < FirstName.length(); i++) {   
char ch = FirstName.charAt(i); // get each character from name
if (Character.isLetter(ch) == false) { // if ch is not letter
System.out.println("*** Invalid FirstName, please try again...");
continue loop1; // continue while loop1 to try again
}
}
break; // if name is valid then break loop and move ahead
}
}
  
public void setLastName() {
Scanner sc = new Scanner(System.in); // to get input from user
loop1: while(true) { // loop1: is label for while loop
System.out.print("please enter Last Name: ");
LastName = sc.nextLine();
// check lastname, and repeat if invalid
for (int i = 0; i < LastName.length(); i++) {
char ch = LastName.charAt(i); // get each character from name
if (Character.isLetter(ch) == false) { // if ch is not letter
System.out.println("*** Invalid LastName, please try again...");
continue loop1; // continue while loop to try again
}
}
break; // if name is valid then break loop1
}
}
  
public void setPeopleSoftId() {
Scanner sc = new Scanner(System.in); // to get input from user
loop1: while(true) { // loop1: is label for while loop
System.out.print("please enter PeopleSoftId: ");
PeopleSoftId = sc.nextLine();
if (PeopleSoftId.length()>7) {
System.out.println("*** max 7 digits are allowed, please try again...");
continue; // continue while loop to try again
}
// check PeopleSoftId, and repeat if invalid
for (int i = 0; i < PeopleSoftId.length(); i++) {
char ch = PeopleSoftId.charAt(i); // get each character from name
if (Character.isDigit(ch) == false) { // if ch is not digit
System.out.println("*** only digits are allowed, please try again...");
continue loop1; // continue while loop to try again
}
}
break; // if name is valid then break loop1
}
}
  
public String setCity() {
String city;
Scanner sc = new Scanner(System.in); // to get input from user
loop1: while(true) { // loop1: is label for while loop
System.out.print("please enter city: ");
city = sc.nextLine();
// check city, and repeat if invalid
for (int i = 0; i < city.length(); i++) {
char ch = city.charAt(i); // get each character from name
if (Character.isLetter(ch) == false && ch!=' ') { // if ch is not letter
System.out.println("*** Invalid city, please try again...");
continue loop1; // continue while loop to try again
}
}
break; // if name is valid then break loop1
}
return city;
}
  
public String setZipcode() {
String zipcode;
Scanner sc = new Scanner(System.in); // to get input from user
loop1: while(true) { // loop1: is label for while loop
System.out.print("please enter zipcode: ");
zipcode = sc.nextLine();
if (zipcode.length()!=9) {
System.out.println("*** zipcode must be 9 digits, please try again...");
continue; // continue while loop to try again
}
// check PeopleSoftId, and repeat if invalid
for (int i = 0; i < zipcode.length(); i++) {
char ch = zipcode.charAt(i); // get each character from zip
if (Character.isDigit(ch) == false) { // if ch is not digit
System.out.println("*** only digits are allowed, please try again...");
continue loop1; // continue while loop to try again
}
}
break; // if name is valid then break loop1
}
return zipcode;
}
  
public String setState() {
String State;
String[] StateNames = {"AK","AL","AR","AZ","CA","CO","CT","DC","DE","FL","GA","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY",
"OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY" };
  
  
Scanner sc = new Scanner(System.in); // to get input from user
loop1: while(true) { // loop1: is label for while loop
System.out.print("please enter State: ");
State = sc.nextLine().toUpperCase(); // make entered state uppercase
// check if state is valid
boolean flag = false;
for (int i = 0; i < StateNames.length; i++) {
if (State.equals(StateNames[i])) {
flag = true; // if state is found in stateNames then set true
}
}
if (flag==false) { // if flag is still false, it means state is not found
for (int i = 0; i < StateNames.length; i++) {
System.out.print( StateNames[i] +" ");
}
System.out.println("\n*** Invalid State, must be one of the above, please try again...");
continue; // continue while loop to try again
}
break; // if state is valid then break loop1
}
return State;
}
  
public void setAddress() {
Scanner sc = new Scanner(System.in); // to get input from user
String line1, city, state, zip;
  
while(true) { // loop1: is label for while loop
System.out.println("please enter Address line1 (house number ");
System.out.print("followed by a space and a street name) : ");
line1 = sc.nextLine();
if (line1.split(" ").length<2) { // if line1 has less than 2 words (houseNumber streetName)
//here line1 is split by space, it gives words array, then that array's length is checked
System.out.println("*** Invalid address line, please try again...");
continue; // continue while loop to try again
}
Address += line1 + ", "; // append to line1 address
break; // exit loop and move ahead
}
Address += setCity() + ", "; // append city to address
Address += setState() + ", "; // append state to address
Address += setZipcode(); // append zipcode to address
}
  
public void getInfo() {
setFirstName();
setLastName();
setPeopleSoftId();
Scanner sc = new Scanner(System.in); // to get input from user
System.out.print("please enter ClassStanding: ");
ClassStanding = sc.nextLine();
  
System.out.print("please enter EmailId: ");
EmailId = sc.nextLine();
  
setAddress();
}
  
public void displayInfo() {
System.out.println(FirstName + " " + LastName +",\t"+PeopleSoftId +",\t"+ ClassStanding +",\t"+ EmailId +",\t"+ Address);
}
}
public class StudentTest {
public static void main(String[] args) {
int N;
Scanner sc = new Scanner(System.in); // to get input from user
  
System.out.print("Enter students count: ");
N = sc.nextInt();
  
Student[] students = new Student[N];
for (int i = 0; i < N; i++) {
students[i] = new Student();
System.out.println("-------- enter details for Student: "+ (i+1) + " of " + N);
students[i].getInfo();
}
  
System.out.println("\nStudents Details, Department of ILT");
System.out.println("-----------------------------------");
for (int i = 0; i < N; i++) {
students[i].displayInfo();
}
System.out.println("-----------------------------------");
System.out.println("Number of students: "+ Student.count);
}
}

//------------ end of StudentTest.java

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a student record management system With JAVA using linked list and queue using Java language...
Create a student record management system With JAVA using linked list and queue using Java language and (oracle or any) database to save files and GUI Java swing to create background The program will have the following properties: A. Register students ( assume each students has ID, first name, last name and middle name) B. Register students with courses ( course no ,course title chr ) C. Able to maintain grade on which course they are registered D. Searches students...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike...
3-students take courses. Someone design this table: Student_Course (student name, ID , SSN , course number,...
3-students take courses. Someone design this table: Student_Course (student name, ID , SSN , course number, grade, home address, course credit ) Description: ID, SSN; each one has a unique value for a given student. Given ID and course number we can get grade. Given SSN and course number we can get grade. Given ID we can get everything except grade and course credit. Given SSN we can get everything except grade and course credit. Given course number we can...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Create the ER Diagram by using the following information. Department Information A department has a name,...
Create the ER Diagram by using the following information. Department Information A department has a name, a web address, a main phone number, an email address and a main mailing address. The address contains street number, street name, city, zip code and state. The entire department address can also be retrieved as a unit. Building Information A building of a campus has a name, number of rooms, number of floors, and a mailing address (similar in format to department address)....
Draw the scenario using Chen notation In a university, department offer courses. Department has instructors who...
Draw the scenario using Chen notation In a university, department offer courses. Department has instructors who teach courses. For a course, the instructor may or may not have a teaching assistant. Each department has a department name, a department code, 1-4 phone numbers, and an address. ◦ Each course has a course number (e.g., INFO605), a section number (e.g., 900), a title, a course type (e.g., online), and units. Each instructor has an instructor ID, first name, last name, gender,...
A loan company wants to design a database to track student loans. Each student attending school...
A loan company wants to design a database to track student loans. Each student attending school is eligible for a loan. A student may have more than one loan. A student may be registered, possibly at different times, in more than one school. Each loan should belong to only one bank. Each bank can approve as many loans as it desires. For each loan, the loan company will track: the student’s SSN, name, address, amount of loan, date of the...
Using the Entities and Attributes you created for your business from the week 1 discussions. Show...
Using the Entities and Attributes you created for your business from the week 1 discussions. Show the tables and relationships resulting from your model in the form of an E/R diagram. You can use PPT, VISIO or any other graphical modeling tool to create your ER diagram. Some of the entities and attributes that I believe my company should have would be: Employees: First Name, Last Name, Employee Address, Employee Phone Number, Employee ID Number, Date of Birth, Social Security...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...