Question

In: Computer Science

Assignment 8 – UML Diagram - Students Class Revised 9/2019 Throughout Chapters 9 & 10, there...

Assignment 8 – UML Diagram - Students Class Revised 9/2019

Throughout Chapters 9 & 10, there are UML class diagrams (Unified Modeling Language) which represent the data fields and methods in a class. From any class given to you, you should be able to design the UML diagram. Likewise, if given a UML, you should be able to define & implement the class.

Please do this in Java please, add comments so it's easy to understand and read so I know how to be able to do it myself.

For the assignment this week, you are given the UML diagram for a class named Students. You will define the Students class and then implement it with a driver program called StudentsDriver.

The StudentsDriver class with the main method should:

• Create an object of the Students class using the no-arg constructor

• get user input for student objects (see sample output below): first name, last name, student id, and birth year and then populate the object using setters (do not use constructors)

• create & initialize 2 objects of the Students class using the overloaded constructor as follows

o first name = Lisa Ann; last name = Larraby; student id = 54321; birth year = 1993 o first name = Karl; last name = Van der Hutten; student id = 54123; birth year = 1983

• call the class toString to display the output for each object as noted in sample output

Validation should be created in the Students class (not driver program):

• Range for student id is 54000 through 54999, inclusive

• Range for student age is from 13 years old to 100 years old, inclusive

• HINTS: in setters for studentID & for birthYear, move the assignment to the appropriate validation method. Then, in each setter, call the appropriate validation method.

*Note: for those already familiar with Java programming, please keep this simple: try/catch, exceptions, GUI, etc. Please use only the concepts discussed up to this point.

Before starting this lab, be sure to refer to the “How to Submit Assignments” document in eLearn for proper documentation, indention, naming conventions, etc. Points may be deducted if submitted incorrectly.

REMINDER: Any sources you use besides the textbook, class demo files, or the instructor must be documented in your program with details such as the scope of help received & URL.

Required project name: LastnameFirstname08 Required package name: chap10 Required class names: as noted above

Sample output. You’re encouraged to use valid, invalid, & boundary test cases. User input in green text:

Enter First Name: Juan Mateo Enter Last Name: Lopez

Enter Student ID: 53500 ID range is 54000 to 54999. Please try again: 53600 ID range is 54000 to 54999. Please try again: 53700 ID range is 54000 to 54999. Please try again: 55000 ID range is 54000 to 54999. Please try again: 56000 ID range is 54000 to 54999. Please try again: 54000

Enter 4-Digit Year of Birth: 1900 Range is 1919 to 2006. Please try again: 1910 Range is 1919 to 2006. Please try again: 1915 Range is 1919 to 2006. Please try again: 2010 Range is 1919 to 2006. Please try again: 2015 Range is 1919 to 2006. Please try again: 1960

Juan Mateo Lopez

Student ID: 54000 Age in 2019: 59 years old

Lisa Ann Larraby

Student ID: 54321 Age in 2019: 26 years old

Karl Van der Hutten Student ID: 54123 Age in 2019: 36 years old

Students

- firstName: String - lastName: String - studentID: int - birthYear: int - CURRENT_YEAR: int - YOUNGEST_AGE:int - OLDEST_AGE:int - LOW_ID:int - HIGH_ID:int

+ Students() + Students(first: String, last: String, studentID: int, birthYear: int)

+ getFirstName(): String + setFirstName (firstName: String): void + getLastName(): String + setLastName (lastName: String): void + getStudentID(): int + setStudentID (studentID: int): void + getBirthYear(): int + setBirthYear(birthYear: int): void + getCurrentYear(): int + getYoungestAge(): int + getOldestAge(): int + getLowId(): int + getHighId(): int

+ validateID(int id): int + validateYr(int yr): int + calcAge(): int + toString(): String <>

You will be graded according to the following rubric (each item is worth one point):

• The Students class is defined exactly & completely as indicated in the UML class diagram.

• Values for constants are used only in initialization and are not hard coded in the methods of the Students class.

• One object is initialized with user input using the Students class setters.

• Two objects are initialized using the Students class overloaded constructor.

• Validation is executed in 2 methods in the Students class.

• In all methods of the Students class, there are no hard coded values.

• Your program compiles & runs.

• You follow standard coding conventions (e.g. variable names, indentation, comments, etc.).

• File name, global comment, citations, etc. as indicated on How to Submit Assignments (Course Overview).

• Your Eclipse project was exported correctly (see Hello World Video Tutorial in Topic 1 Learning Activities).

Solutions

Expert Solution

//Java code

package chap10;

import java.util.Scanner;

public class Students {
private String firstName;
private String lastName;
private int studentID;
private int birthYear;
private final int CURRENT_YEAR=2019;
private final int YOUNGEST_AGE =13;
private final int OLDEST_AGE = 100;
private final int LOW_ID = 54000;
private final int HIGH_ID = 54999;

//No arg Constructor
public Students()
{
firstName="";
lastName ="";
studentID =0;
birthYear = 0;
}
//Constructor with args

public Students(String firstName, String lastName, int studentID, int birthYear) {
setFirstName(firstName);
setLastName(lastName);
setBirthYear(birthYear);
setStudentID(studentID);
}


//getters and setters

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public int getStudentID() {
return studentID;
}

public void setStudentID(int studentID) {
Scanner input = new Scanner(System.in);
while (validateID(studentID)==-1)
{
System.out.print("ID range is "+getLowId()+" to "+getHighId()+". Please try again: ");
studentID = input.nextInt();
}

this.studentID = studentID;
}

public int getBirthYear() {
return birthYear;
}

public void setBirthYear(int birthYear) {
Scanner input = new Scanner(System.in);
while (validateYr(birthYear)==-1)
{
System.out.print("Range is 1919 to 2006. Please try again:");
birthYear = input.nextInt();
}
this.birthYear = birthYear;
}
public int getCurrentYear()
{
return CURRENT_YEAR;
}
public int getYoungestAge()
{
return YOUNGEST_AGE;
}
public int getOldestAge()
{
return OLDEST_AGE;
}
public int getLowId()
{
return LOW_ID;
}
public int getHighId()
{
return HIGH_ID;
}
public int validateID(int id)
{
if(id >= LOW_ID && id<= HIGH_ID)
return id;
else
return -1;
}
public int validateYr(int yr)
{
birthYear = yr;
int age = calcAge();
if(age >= YOUNGEST_AGE && age<=OLDEST_AGE)
{
return yr;
}
else {
birthYear =0;
return -1;

}
}
public int calcAge()
{
return getCurrentYear()-birthYear;
}

@Override
public String toString() {
return firstName+" "+lastName+"\n Student ID: "+studentID+" Age in "+getCurrentYear()+": "+calcAge()
+" years old";
}
}

//=================================================

package chap10;

import java.util.Scanner;

public class StudentsDriver {
public static void main(String[] args)
{
String firstName,lastname;
int birthYear,id;
Scanner input = new Scanner(System.in);
/**
* Create an object of the Students class using the no-arg constructor
*/
Students student1 = new Students();
System.out.print("Enter First Name: ");
firstName = input.nextLine();
student1.setFirstName(firstName);
System.out.print("Enter Last Name: ");
lastname = input.nextLine();
student1.setLastName(lastname);
System.out.print("Enter Student ID: ");
id = input.nextInt();
student1.setStudentID(id);
System.out.print("Enter 4-Digit Year of Birth:: ");
birthYear = input.nextInt();
student1.setBirthYear(birthYear);

/**
* create & initialize 2 objects of the Students class using
* the overloaded constructor
*/
Students student2 = new Students("Lisa Ann", "Larraby",54321,1993);
Students student3 = new Students("Karl","Van der Hutten",54123,1983);

//Display all three students
System.out.println(student1);
System.out.println(student2);
System.out.println(student3);
}
}

//Output

// If you need any help regarding this solution... please leave a comment ...... Thanks


Related Solutions

draw a uml diagram for a class
draw a uml diagram for a class
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart...
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart or another diagramming tool. If you can’t find a diagramming tool, you can hand draw the diagram but make sure it is legible. Points to remember: • Include all classes on your diagram. There are nine of them. • Include all the properties and methods on your diagram. • Include the access modifiers on the diagram. + for public, - for private, ~ for...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student...
HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student class. - id : Integer - units : Integer - name : String + Student ( ) : + Student (id : Int, name : String, units : Int) : + ~Student( ) : + setID(id : Integer) : void + setName(name: String) : void + setUnits(units : Integer ) : void + displayRecord() : void 2.)   Include 3 files: -   Source.cpp -   Student.h...
A UML class diagram can be used to model UML by considering each graphical component of...
A UML class diagram can be used to model UML by considering each graphical component of the notation to be a class. For example, a class diagram contains a collection of classes. Your problem is to construct and draw one class diagram with the below UML elements. That is, there will be a class for each of the elements listed. You must also provide ALL of the relationships between each of these classes. The elements to model in the class...
Draw a UML diagram that describes a class that will be used to describe a product...
Draw a UML diagram that describes a class that will be used to describe a product for sale on Glamazon.com. The product has a name, a description, a price, ratings by many customers (1 to 5 stars), and a group of customer comments. New products have no ratings or comments by customers, but do have a name, description and price. The price can be changed and more customer ratings and comments can be added. A global average rating of all...
Complete the following class UML design class diagram by filling in all the sections based on...
Complete the following class UML design class diagram by filling in all the sections based on the information given below.         The class name is Boat, and it is a concrete entity class. All three attributes are private strings with initial null values. The attribute boat identifier has the property of “key.” The other attributes are the manufacturer of the boat and the model of the boat. Provide at least two methods for this class. Class Name: Attribute Names: Method...
What would the pseudocode look like for this UML class diagram? Class - oranges: String -...
What would the pseudocode look like for this UML class diagram? Class - oranges: String - bananas: String - grapes: String - apples: String + Class(String bananas, String grapes, String apples) + oranges( ): void + isValidGrapes( ): boolean + isValidApples( ): boolean + getOranges( ): String + getBananas( ): String + setBananas(String bananas): void + getGrapes( ): String + setGrapes(String grapes): void + getApples( ): String + setApples(String apples): void
Given the following UML class diagram, implement the class as described by the model. Use your...
Given the following UML class diagram, implement the class as described by the model. Use your best judgment when implementing the code inside of each method. +---------------------------------------------------+ | Polygon | +---------------------------------------------------+ | - side_count : int = 3 | | - side_length : double = 1.0 | +---------------------------------------------------+ | + Polygon() | | + Polygon(side_count : int) | | + Polygon(side_count : int, side_length : double) | | + getSides() : int | | + setSides(side_count : int) | |...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT