Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework 4: Department 1 Objective This project is the first time youll create your own objects, along with private data, methods, etc. This isnt a

Homework 4: Department

1 Objective

This project is the first time youll create your own objects, along with private data, methods, etc. This isnt a complete working system with a user interface; its just a chance for you to create classes, then instantiate and test them. Youll create two supplier classes that interact with each other (through a has a relationship).

2 Objects Youll Create

Here are UML Class Diagrams for the objects you are to create. Pay attention to the diagram notation indicating whether methods are public (+) or private (-); ask questions if you need clarification. Understanding the model is of critical importance here.

Student

Department

(you figure out the private data needed)

(you figure out the private data needed)

Constructors

+Student(firstName : String, lastName : String, id : String)

+Student(firstName : String, lastName : String, id : String, csc110 : Boolean, csc142 : Boolean, csc143 : Boolean)

Accessors

+getFirstName() : String

+getLastName() : String

+getID() : String

+getCSC110() : Boolean

+getCSC142() : Boolean

+getCSC143() : Boolean

+getBalance() : Double

+toString() : String

Mutators

+settFirstName() : String

+setLastName() : String

+setID() : String

+setCSC110(csc110 : Boolean)

+setCSC142(csc142 : Boolean)

+setCSC143(csc143 : Boolean)

Constructors

+Department()

+Department(totalStud110 : Integer, totalStud142 : Integer, totalStud143 : Integer, totalBalance : Double)

Accessors

+getTotalCSC110 () : Integer

+getTotalCSC142 () : Integer

+getTotalCSC143 () : Integer

+getTotalStudents() : Integer

+getTotalBalance() : Double

+getTotalGr110() : Integer

+getTotalGr142() : Integer

+getTotalGr143() : Integer

+toString() : String

Other Methods

+addStudent(newStudent : Student) : void

3 Constraints and Assumptions

Create no static methods except for the test methods.

Mark each instance variable and each method as either public or private; follow the UML where it gives guidance and make smart decisions where it doesnt.

Use exactly the method names shown. Look carefully at the parameter data types and the return data types; they give you clues.

Departments addStudent() method maintains the appropriate total students of each group and the total balance.

Departments getTotalGr methods calculate how many groups need for each class (28 students in the class).

The toString() method should do their best to summarize the state of the object instance in questions; include newlines in the strings to make the result displayable and attractive.

Create a test method for each class that checks every constructor and every method except toString.

One credit equals 5, and one credit costs $110.

Throw an IllegalArgumentException if any of these preconditions are violated:

o A first name, last name, and ID can't be empty.

o Total students of each group can't be negative.

4 Code Implementation

Follow the provided Course Style Guide.

Dont use magic numbers, create constants for credits, credit price and the number of students in one class.

5 Testing

The testing required here is significant. You may spend as much time writing your tests as you do writing the entire rest of the code. Your test code needs to test everything (or nearly everything), your object can do; dont treat it lightly. Dont forget to test constructors and preconditions. And dont forget test code is still code and can have bugs, so be suspicious if everything passes miraculously the first time, i.e., test that you can induce failures and get the appropriate error messages shown.

6 Submitting Your Work

Youll be creating two java classes (.java) files; zip them and submit them as a single file (e.g., in a .zip file). BlueJ can also create .jar files; be sure and specify include source if you use this method.

7 Hints

Dont duplicate code; avoid this wherever possible. As an example, dont forget its legal for one constructor to call another constructor; this is good practice and helps avoid duplication and the creation of extra code paths to test.

public class Main

{

public static void main(String[] args){

Student newStud=new

Student("Name","LastName","123456789",false,true,false);

//Check the Student class

System.out.println(newStud.toString());

//Check the class department

Department newDep=new Department();

for(int i=0;i<98;i++){

newDep.addStudent(new

Student("Name"+i,"LastName"+i,"3333"+i,true,false,false));

}

for(int i=0;i<51;i++){

newDep.addStudent(new

Student("Name"+i,"LastName"+i,"4444"+i,false,true,false));

}

for(int i=0;i<27;i++){

newDep.addStudent(new

Student("Name"+i,"LastName"+i,"5555"+i,false,false,true));

}

System.out.println(newDep.toString());

// System.out.println("How to compare two variables with float

point.");

// double num1 = 10 / 3.0;

// double num2 = 3.333334;

// String s1 = String.format("%.2f", num1);

// String s2 = String.format("%.2f", num2);

// System.out. println(num1 + " = " + num2 + " is " + (num1 ==

num2));

// System.out. println(num1 + " = " + num2 + " is " +

s1.equals(s2));

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

LO4 Provide an overview of four challenges facing HR today.

Answered: 1 week ago