0% found this document useful (0 votes)
167 views7 pages

Lighting Store 500

The document describes a programming assignment to create an object-oriented program to manage a lighting store. The program must: 1. Allow users to log in and have administrator or user roles. 2. Load and save data to CSV files for customers, manufacturers, orders and lamps. 3. Perform lamp management, sales, search and statistics functions like adding/editing lamps and orders, searching lamps, and viewing inventory and sales statistics. 4. Model lamps, customers, manufacturers and orders as classes with attributes like ID, name, price. 5. Implement a menu system using enum types to navigate program functions based on user role.

Uploaded by

Hoàng Phạm
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)
167 views7 pages

Lighting Store 500

The document describes a programming assignment to create an object-oriented program to manage a lighting store. The program must: 1. Allow users to log in and have administrator or user roles. 2. Load and save data to CSV files for customers, manufacturers, orders and lamps. 3. Perform lamp management, sales, search and statistics functions like adding/editing lamps and orders, searching lamps, and viewing inventory and sales statistics. 4. Model lamps, customers, manufacturers and orders as classes with attributes like ID, name, price. 5. Implement a menu system using enum types to navigate program functions based on user role.

Uploaded by

Hoàng Phạm
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/ 7

Type: Long Assignment

LAB 211 Assignment Code:


LOC: 500
Slot(s): N/A

Title
Lighting store

Background
Write a program to manage a store that sells household lighting equipment. The program is
implemented object-oriented (design patterns can be applied).
Lamps are classified as follows: incandescent, fluorescent, and LED lamps.

 Incandescent information includes:


- Id
- Name
- Wattage
- Manufacturer
- Date of manufacture
- Warranty period (in months)
- Import unit price
- Selling unit price
- Inventory number
 Fluorescent information includes:
- Id
- Name
- Wattage
- Bulb length
- Manufacturer
- Date of manufacture
- Warranty period (in months)
- Import unit price
- Selling unit price
- Inventory number
 LED information includes:
- Id
- Name
- Wattage
- LED type
- Manufacturer
- Date of manufacture
- Warranty period (in months)
- Import unit price
- Selling unit price
- Inventory number
 Order information includes:
- Id
- Customer id
- List of lights and purchase quantity
 Customer information includes:
- Id
- Name
- Phone number (uniqueue)
 Manufacturer information includes:
- Id
- Name
In addition, to protect the environment, the state collects an additional environmental tax of 20%
on fluorescent and 35% on incandescent lamps.
Features:
The program has the following functions:
1. Login (50 points)
To use the functions, require the user to log in to the system as an administrator or user role.
Require (username and password).
2. Load/Save data (100 points)
Function to read and write data to a CSV file.
3. Lamp product management (50 points)
The function allows the user to add, remove, or edit lamps.
4. Sales functions (100 points)
The function allows the user to add, remove, or edit orders.
5. Search functions (100 points)
Lamp search function by lamp name, lamp type, wattage, manufacturer ...
6. Statistics functions (100 points)
a) Inventory statistics (50 points)
The function displays a list of lights filtered by lamp type and sorted in ascending order
by inventory quantity.
b) Sales statistics (50 points)
The function displays a list of lights sorted in descending order by sales in the quarter
(quarter 1, 2, 3, 4) and by lamp type.
Hints
1. Class Order: Use collection Map<Lamp, Integer> to store order lines
2. Use enum type to present lamp type
public enum LampType {
INCANDESCENT,
FLUORESCENT,
LED
}

3. Use enum type to present UserRole


public enum UserRole {
ADMIN(0),
USER(1),
INVALID(-1);

private final int role;

public static UserRole valueOf(int role) {


if (role < 0 || role >= UserRole.values().length) {
return UserRole.INVALID;
}
return UserRole.values()[role];
}

private UserRole(int role) {


this.role = role;
}

public int intValue() {


return this.role;
}
}
4. Use enum type to create menu items
public enum MenuItem{
BACK("Back", UserRole.USER),
EXIT("Exit", UserRole.USER),

LAMP_FUNCTIONS("Lamp functions", UserRole. USER),


LAMP_ADD("Add new", UserRole.ADMIN),
....
SALES_ FUNCTIONS("Sales functions", UserRole. USER),
SALES_ADD("Add new", UserRole.ADMIN).
....
INVENTORY_ FUNCTIONS("Inventory functions", UserRole. USER),
INVENTORY_STATISTIC(“Inventory statistic”, UserRole.USER),
SALES_STATISTIC(“Sales statistic”, UserRole.USER);

private final String label;


private final UserRole role;
public String getLabel() {
return label;
}

public UserRole getRole() {


return role;
}

private MenuItem(String label, UserRole role) {


this.label = label;
this.role = role;
}
}

5. Class Menu
public class Menu {

private MenuItem mainChoice;


private MenuItem subChoice;

private static final MenuItem[] mainOptions = {


MenuItem.EXIT,
MenuItem.LAMP_FUNCTIONS,
MenuItem.SALES_ FUNCTIONS,
MenuItem.SEARCH_ FUNCTIONS,
MenuItem.INVENTORY_ FUNCTIONS,
MenuItem.CUSTOMER_ FUNCTIONS,
MenuItem.MANUFACTURER_ FUNCTIONS
};

private static final MenuItem[] lampSubOptions = {


MenuItem.BACK,
MenuItem.LAMP_ADD,
MenuItem.LAMP_UPDATE,
MenuItem.LAMP_DELETE
};
private static final MenuItem[] salesSubOptions = {
MenuItem.BACK,
MenuItem.SALES_ADD,
MenuItem.SALES_UPDATE,
MenuItem.SALES_DELETE
};

private static final MenuItem[] inventorySubOptions = {


MenuItem.BACK,
MenuItem.INVENTORY_STATISTIC,
MenuItem.SALES_STATISTIC
};

.....

public Menu() {
this.mainChoice = MenuItem.EXIT;
this.subChoice = MenuItem.BACK;
}

public MenuItem getUserChoice() {


if (this.subChoice == MenuItem.BACK || this.subChoice == this.mainChoice) {
this.mainChoice = getChoice(null);
}
if (this.mainChoice != MenuItem.EXIT) {
this.subChoice = getChoice(this.mainChoice);
}
return this.mainChoice != MenuItem.EXIT ? this.subChoice : MenuItem.EXIT;
}

private MenuItem getChoice(MenuItem item) {


MenuItem[] menuOptions = getOptions(item);
if (menuOptions == null) {
return this.mainChoice;
}
showMenu(menuOptions);
int opt = Util.inputInt("Mời chọn chức năng", 0, menuOptions.length - 1);
return menuOptions[opt];
}

private MenuItem[] getOptions(MenuItem item) {


MenuItem[] menuOptions;
if (item == null) {
return Menu.mainOptions;
}

switch (item) {
case LAMP_FUNCTIONS:
menuOptions = Menu.lampSubOptions;
break;
case SALES_ FUNCTIONS:
menuOptions = Menu.salesSubOptions;
break;
case SEARCH_ FUNCTIONS:
menuOptions = Menu.searchSubOptions;
break;
case INVENTORY_ FUNCTIONS:
menuOptions = Menu.inventorySubOptions;
break;
case CUSTOMER_ FUNCTIONS:
menuOptions = Menu.customerSubOptions;
break;
case MANUFACTURER_ FUNCTIONS:
menuOptions = Menu.manufacturerSubOptions;
break;
default:
menuOptions = Menu.mainOptions;
}
return menuOptions;
}

private void showMenu(MenuItem[] menuOptions) {


System.out.println("**********************");
for (int i = 1; i < menuOptions.length; i++) {
System.out.println(i + ": " + menuOptions[i].getValue());
}
System.out.println("0: " + menuOptions[0].getValue());
}
}

6. Class main
private void process() {
Menu menu = new Menu();
MenuItem userChoice = null;
do {
userChoice = menu.getUserChoice();
switch (userChoice) {
case LAMP_ADD:
addNewLamp();
break;
case LAMP_UPDATE:
........
.......

default:
System.out.println("chưa cài đặt");
}
} while (userChoice != MenuItem.EXIT);
}

7. File database
File Customers.csv Description
C0001,Nguyễn Ngọc Nam,0909012345 Information in a line:
C0002,Trần Hoàng Hải,0916211022 <ID,Name,Phone number>

File Manufacturers.csv Description


M0001,Rạng Đông Information in a line:
M0001, Philips <ID,Name>
File Orders.csv Description
O0001,C0001,L0001,1 Information in a line:
O0001,C0001,L0002,3 <ID,Customer id,Lamps Id,Quantity>
O0002,C0002,L0001,3
O0003,C0001,L0002,2
O0004,C0003,L0001,1
O0004,C0003,L0004,3

File Lamps.csv Description


L0001,INCANDESCENT,... Information in a line:
L0002,FLUORESCENT,... <ID, Lamps Type,Name,Wattage, ...>
L0002,LED,...

-----Hết-----

You might also like