Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
81 views3 pages

Workshop 2

This document outlines a 3-part workshop on classes and objects in Java. [Part 1] involves drawing a UML class diagram for a guitar shop management app with Guitar and Inventory classes. [Part 2] provides instructions to implement the Guitar class with fields, constructors, and methods. [Part 3] asks the student to create an employee management program with an Employee class that allows entering, printing, updating, and removing employee data. Completing the workshop will help students design and implement classes, create objects, and describe what they have learned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views3 pages

Workshop 2

This document outlines a 3-part workshop on classes and objects in Java. [Part 1] involves drawing a UML class diagram for a guitar shop management app with Guitar and Inventory classes. [Part 2] provides instructions to implement the Guitar class with fields, constructors, and methods. [Part 3] asks the student to create an employee management program with an Employee class that allows entering, printing, updating, and removing employee data. Completing the workshop will help students design and implement classes, create objects, and describe what they have learned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Workshop #2: Class and Object

Learning Outcomes:

Upon successful completion of this workshop, you will have demonstrated the abilities to:

 Design and implement a class.


 Create an object from a class
 Describe to your instructor what you have learned in completing this workshop.

Requirements:

Part 1: Find classes and use UML to draw class structure [2 points]

Problem: Mr. Hung is the owner of the shop that sells guitars. He wants you to build him a shop
management app. This app is used for keeping track of guitars. Each guitar contains
serialNumber, price, builder, model, back Wood, top Wood. The guitar can create a melodious
sound. The shop will keep guitars in the inventory. The owner can add a new guitar to it, he
search also the guitar by the serialNumber.

Requirement: Write your paper down classes in the problem and use UML draw class structure.

Note: show members of a class: fields and methods

Do it yourself before getting help

Guideline:

Apply design guideline :

 Main nouns: Guitar


 Auxiliary nouns describe details of the guitar:serialNumber, price, builder, model, back
Wood, top Wood.
 Verbs describe behaviors of the guitar: create Sound

Continue finding other nouns


 Main nouns: Inventory
 Auxiliary nouns describe details of the inventory: the list(array) of guitars
 Verbs describe behaviors of the inventory: add a new guitar, search the guitar by
serialNumber.
Using UML to draw a class diagram

Part 2: Implement the Guitar [3 points].

Step by step workshop instructions:


- Create a new project named “workshop2”
- In the project, create a new file named “Guitar.java”

1
o Declare fields with access modifier as private: String serialNumber, int price,
String builder, String model, String backWood, String topWood
o Declare and implement methods with access modifier as public:
 public Guitar() {…} : to assign all fields to empty values

 public Guitar( String serialNumber, int price, String builder, String model,
String backWood, String topWood) {…}: to assign all fields by input
parameters

 public String getSerialNumber(){…}: return the value of the field


serialNumber.

 public void setSerialNumber(String serialNumber){…}: if the input


parameter is not empty then assign it to the field serialNumber.

 Implement getter/setter of all other fields

 public void createSound(){…}: in the method, invoke all getters and use
System.out to print out values after getting.

- In the project, create a new file named “Tester.java. Create the method main in here,
you type:

public class Tester {


public static void main(String[] args) {
Guitar obj1=new Guitar();
Guitar obj2=new Guitar("G123",2000,"Sony","Model123","hardWood","softWood");
System.out.println("State of obj1:");
obj1.createSound();
System.out.println("State of obj2:");
obj2.createSound();

System.out.println("set price = 3000 of obj1");


obj1.setPrice(3000);
System.out.println("get price of obj1:" + obj1.getPrice() );
}
}

The output is:

2
Part 3: Implement Employee management program [5 point]

- Write an employee management program for Fsoft according to the following


description:
- Employee information: Code, Fullname, Phone, Salary, Salary coefficient, department.
- The program allows the user to enter the number of employees.
- Print out the list of employees.
- Print out the total salary of the employees.
- Update employee salary based on the employee code entered by the user.
- Remove an employee based on the employee code entered by the user.

You might also like