Question

CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!)....

CS 2050 – Programming Project # 1

Due Date: Session 3 (that is, in one week!). Can be resubmitted up to two times until Session 6 if your first version is submitted by session 3.

In this project, you create two classes for tracking students. One class is the Student class that holds student data; the other is the GradeItem class that holds data about grades that students earned in various courses.

Note: the next three projects build on this one. To keep pace in the course, you should complete this project in full by the due date. Ask questions if you’re stuck!

Use Javadoc parameters @author, @version, @param and @return, as needed.


Problem Scenario

State University needs a Java programmer to assist it with creating a grade book application. You have graciously volunteered to help. The university wants to track their students and their grades in various courses. For each student, the university wants to track this information:

  1. Student id (String – a unique value for each student)
  2. Student first name (String)
  3. Student last name (String)
  4. Student email address (String – a unique value for each student)

The university wants to make sure that they have a correct email address for each student. They want you to verify there is an “@” in the email address.

For each grade item, the university wants to track this information:

  1. Student id (String – should match a student in the student list)
  2. GradeItem id (Integer – a unique value for each grade item)
  3. Course id (String)
  4. Item type (String – must be one of the following: HW, Quiz, Class Work, Test, Final)
  5. Date (String – format yyyymmdd)
  6. Maximum score (Integer – must be greater than 0)
  7. Actual score (Integer – must be in the range of 0 to maximum score)

Program Requirements

Create two classes for the problem scenario given above. The classes are:

  1. A Student class
  2. A GradeItem class

These two classes are used in subsequent projects to instantiate the Student and GradeItem objects, and do not contain a main method or any input/output code. After declaring your instance variables, your Student and GradeItem classes should each contain these methods in this order:

  1. Constructor
  2. Get methods for each private variable (“getters”)
  3. An equals method to determine whether two instances of an object contain exactly the same data
  4. A toString method to display an instance of an object

Note: We assume that our objects are immutable (unchanged once an object is instantiated) so we don’t need any set (“setter”) methods.

Constructors in each class should validate the data as follows:

  1. In the Student class
    • Ensure all values for String fields are not blank. These are the student id, first name, last name and email address.
    • Ensure the student email address contains the “@” character. Hint: Use the contains method in the String class.
  2. In the GradeItem class
    • Ensure all values for String fields are not blank. These are the student id, course id, item type and date.
    • All grade item types must be one of the following: HW, Quiz, Class Work, Test, or Final. Use an array to store the types and search that array for a valid type. The entries are case‑sensitive (“HW” does not equal “Hw”). Do not hard-code the grade item types.
    • GradeItem class: Maximum score must be greater than 0.
    • GradeItem class: Actual score must be in the range of 0 to maximum score.

If any of the data in either class is invalid, the constructor in which the error was detected must throw the IllegalArgumentException exception with a message that is meaningful to a non-technical user.

Note: The data required to initialize the fields is passed by a method (defined in a subsequent project) to the constructor using arguments. In the Student and GradeItem classes, do not display any error messages on the console or in a window, or use the Scanner class to ask users for input.

Testing

We will write code to test the data in the Student and GradeItem classes in Programming Project # 2. Other than the testing described above, there is no additional testing now.

What to Submit

Submit printed copies of the Student class on top of the GradeItem class and staple them together. Write your name and Project #1 in the upper right-hand corner of the first page. Resubmitting? Place the earlier submission(s) at the end and indicate on the top page of the new submission that you are resubmitting.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
* @author Author Name
* @version Version Number
*/

class Student
{
// Private Instance variables of the class Student
private String StudentId;
private String FirstName;
private String LastName;
private String EmailId;
  
// Constructor - to validate all the fields of the class when an object gets instantiated
public Student(String studentid,String firstname,String lastname,String emailid){
  
// Try..catch block is used to handle the IllegalArgumentException
try{
  
// the first four If conditions check if the fields StudentId, Firstname, Lastname, EmailId are blank.
// If so, it raises an exception.

if(studentid.equals(" "))
throw new IllegalArgumentException("Student ID is blank");
if(firstname.equals(" "))
throw new IllegalArgumentException("First Name is blank");
if(lastname.equals(" "))
throw new IllegalArgumentException("Last Name is blank");
if(emailid.equals(" "))
throw new IllegalArgumentException("Email ID is blank");
  
// the condition checks if the @ symbol is present in the email address to validate the same.
if(emailid.contains("@")==false)
throw new IllegalArgumentException("Email ID is invalid");
  
// if all the above conditions are valid, the object gets created and the values are assigned to the variables
else
{
StudentId = studentid;
FirstName = firstname;
LastName = lastname;
EmailId = emailid;
}
  
}catch(IllegalArgumentException ex) {} // the excpetion must be caught or it will result in compilation error
}
  
//public getters for the private instance variables
public String getStudentId(){
return StudentId;
}
public String getFirstName(){
return FirstName;
}
public String getLastName(){
return LastName;
}
public String getEmailId(){
return EmailId;
}
/**
* @param s1 the first Student object to compare with
* @param s2 the second Student object to compare with
* @return true/false indicating if the objects are equal or not.
*/

public boolean equals(Student s1,Student s2)
{
if(s1.equals(s2))
return true;
else
return false;
}
  
//Method toString() is to print the student record in neat format
public String toString(){

String s = "STUDENT INFORMATION \n";
s = s + "First Name : " + FirstName + "\n";
s = s + "Last Name : " + LastName + "\n";
s = s + "Student Id : " + StudentId + "\n";
s = s + "Email Id : " + EmailId + "\n";
  
return s;
}
  
}
class GradeItem
{
// Private Instance variables of the class GradeItem
private String StudentId;
private int ItemId;
private String CourseId;
private String ItemType;
private String GradeDate;
private int MaxScore;
private int ActualScore;
  
// Constructor - to validate all the fields of the class when an object gets instantiated
public GradeItem(String studentid,int itemid,String courseid,String itemtype,String gradedate,int maxscore,int actualscore){
try{
String[] gradetypes = {"HW","Quiz","Class Work","Test","Final"};
  
// the first four If conditions check if the fields StudentId, CourseId, ItemType, GradeDate are blank.
// If so, it raises an exception.
if(studentid.equals(" "))
throw new IllegalArgumentException("Student ID is blank");
if(courseid.equals(" "))
throw new IllegalArgumentException("Course ID is blank");
if(itemtype.equals(" "))
throw new IllegalArgumentException("Item Type is blank");
if(gradedate.equals(" "))
throw new IllegalArgumentException("Date is blank");
  
// the for loop checks each valid type with the GradeType and raises an exception if it is invalid.   
// a variable found is set to false..if a match is identified in the for loop , it sets found variable to true and quits
// if found is false, then an exception is raised.

boolean found=false;
for(String type: gradetypes){
if(type.equals(itemtype))
{
found=true;
break;
}
else
found=false;
}
if (found==false)
throw new IllegalArgumentException("The Item Type is invalid");
  
// raising exception if MaxScore is less or equal to zero.
if(maxscore<=0)
throw new IllegalArgumentException("Max Score must be greater than zero");

// raising exception if ActualScore must be between 0 and maxscore.
if((actualscore<0)||(actualscore>maxscore))
throw new IllegalArgumentException("Max Score must be between 0 and " + maxscore);
  
// if all the above conditions are valid, the object gets created and the values are assigned to the variables
else
{
StudentId = studentid;
ItemId = itemid;
CourseId = courseid;
ItemType = itemtype;
GradeDate = gradedate;
MaxScore = maxscore;
ActualScore = actualscore;
}   
}catch(IllegalArgumentException ex) {}
}
  
//public getters for the private instance variables
public String getStudentId(){
return StudentId;
}
public String getCourseId(){
return CourseId;
}
public String getItemType(){
return ItemType;
}
public String getGradeDate(){
return GradeDate;
}
public int getItemId(){
return ItemId;
}
public int getMaxScore(){
return MaxScore;
}
public int getActualScore(){
return ActualScore;
}
  
/**
* @param g1 the first GradeItem object to compare with
* @param g2 the second GradeItem object to compare with
* @return true/false indicating if the objects are equal or not.
*/

public boolean equals(GradeItem g1,GradeItem g2)
{
if(g1.equals(g2))
return true;
else
return false;
}
  
//Method toString() is to print the Grade record in neat format
public String toString(){

String s = "GRADE INFORMATION \n";
s = s + "Student Id : " + StudentId + "\n";
s = s + "Item Id : " + ItemId + "\n";
s = s + "Course Id : " + CourseId + "\n";
s = s + "Item Type : " + ItemType + "\n";
s = s + "Date : " + GradeDate + "\n";
s = s + "Max. Score : " + MaxScore + "\n";
s = s + "Actual Score : " + ActualScore + "\n";
return s;
}
}

//To customize the displayed message , the IllegalArgumentException is implemented.
class IllegalArgumentException extends Exception
{
public IllegalArgumentException(String s)
{
super(s);
}
}

===============================================================================

Sample output: ( hint : used System.out.println() in toString() method just to show sample output here

STUDENT INFORMATION
First Name : aaa
Last Name : laaa
Student Id : s01
Email Id : [email protected]

GRADE INFORMATION
Student Id : s01
Item Id : 45
Course Id : c87
Item Type : HW
Date : 20190202
Max. Score : 100
Actual Score : 78

=================================================================================

Best Wishes....

Add a comment
Know the answer?
Add Answer to:
CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!)....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Page 1/2 ECE25100 Object Oriented Programming Lab 8: Inheritance Description: The purpose of this lab is...

    Page 1/2 ECE25100 Object Oriented Programming Lab 8: Inheritance Description: The purpose of this lab is to practice inheritance. To get credit for the lab, you need to demonstrate to the student helper that you have completed all the requirements. Question 1: Consider the following detailed inheritance hierarchy diagram in Fig. 1. 1) The Person.java constructor has two String parameters, a first name and a last name. The constructor initializes the email address to the first letter of the first...

  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • ( Object array + input) Write a Java program to meet the following requirements: 1. Define...

    ( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...

  • The Code need to be in C# programming language. could you please leave some explanation notes...

    The Code need to be in C# programming language. could you please leave some explanation notes as much as you can? Thank you Create the following classes in the class library with following attributes: 1. Customer a. id number – customer’s id number b. name –the name of the customer c. address – address of the customer (use structs) d. telephone number – 10-digit phone number e. orders – collection (array) of orders Assume that there will be no more...

  • Write java program The purpose of this assignment is to practice OOP with Array and Arraylist,...

    Write java program The purpose of this assignment is to practice OOP with Array and Arraylist, Class design, Interfaces and Polymorphism. Create a NetBeans project named HW3_Yourld. Develop classes for the required solutions. Important: Apply good programming practices Use meaningful variable and constant names. Provide comment describing your program purpose and major steps of your solution. Show your name, university id and section number as a comment at the start of each class. Submit to Moodle a compressed folder of...

  • Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses:...

    Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses: Exception handling File Processing(text) Regular Expressions Prep Readings: Absolute Java, chapters 1 - 9 and Regular Expression in Java Project Overview: Create a Java program that allows a user to pick a cell phone and cell phone package and shows the cost. Inthis program the design is left up to the programmer however good object oriented design is required.    Project Requirements Develop a text...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • Create an abstract Student class for Parker University. The class contains fields for student ID number,...

    Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for...

  • This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description:...

    This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT