0% found this document useful (0 votes)
2 views

Assignment 1 Documentation

The document outlines a series of programming exercises focused on creating classes for various applications, including a chat user system, invoice management, computer inventory, mathematical calculations, and DNA sequence operations. Each exercise details class structures, attributes, methods, and implementation strategies to meet specific requirements. The exercises emphasize object-oriented programming principles such as encapsulation, constructors, and method functionality.

Uploaded by

Edi Mehaj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 1 Documentation

The document outlines a series of programming exercises focused on creating classes for various applications, including a chat user system, invoice management, computer inventory, mathematical calculations, and DNA sequence operations. Each exercise details class structures, attributes, methods, and implementation strategies to meet specific requirements. The exercises emphasize object-oriented programming principles such as encapsulation, constructors, and method functionality.

Uploaded by

Edi Mehaj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CEN215

Assignment 1

REPORT / ANALYSIS OF EXERCISES

Worked by : EDVIN MEHAJ

Group: A
Exercise 1: Chat Users

The task is to create a class named ChatUser with the following attributes:

 Nickname
 Age
 Location

The requirements include:

1. Four constructors with varying parameters to initialize the object.


2. Methods to retrieve attribute values (get methods) and modify the location (setLocation
method).
3. A method to display the user's status (printStatus).

The implementation must ensure:

 Each user has a unique nickname when the default constructor is used.
 Constructed users display a message confirming their addition to the chat.
 Encapsulation of attributes with private access.

To design the class I used private fields: nickname, age, location and a static counter to create
unique nicknames for each user. Also I used a status variable to tell if a user is in the chat or no.
Constructors:
No-parameter constructor: Assigns default values (Anonymous<number>, age = 20, location =
"U.S.A").
Single-parameter constructor: Accepts age, uses default nickname and location.
Two-parameter constructor: Accepts nickname and age, sets location to "U.S.A".
Three-parameter constructor: Fully custom initialization.
In order to create different default usernames at the no parameter constructor and single
parameter constructor I use a counter which increments every time a new user is created.
Exercise 2: Invoice

The task is to create an Invoice class that encapsulates the details of a customer invoice. The
class includes features to handle customer data, items purchased, taxation, discounts, and overall
invoice management.

Class Design

1. Invoice Class

Represents an invoice with attributes and methods to manage its lifecycle.

 Attributes:
o UUID id: Unique identifier for the invoice.
o LocalDate dateCreated: Date the invoice is issued.
o LocalDate dueDate: Defaults to 7 days after the issue date.
o Customer customer: Customer information.
o Item[] itemList: Array of up to 10 items.
o boolean isListEmpty: Tracks whether the item list is empty.
 Methods:
o addItems(): Dynamically add items to the invoice (max 10).
o calcDiscount(): Applies a 10% discount if the total cost exceeds 5000 ALL.
o valueAddedTax(): Calculates VAT as 20% of the total cost.
o totalCost(): Computes the total price of all items before discounts or VAT.
o toalAfterDiscount(): Computes the total cost after discounts and VAT.
o toString(): Provides a detailed invoice summary.

2. Customer Class

Represents the customer associated with the invoice.

 Attributes:
o String name: Customer name.
o String email: Email address.
o String address: Physical address.
 Methods:
o Default and parameterized constructors.
o Getters and setters for all attributes.
o toString(): Formats customer details for display.
3. Item Class

Encapsulates individual items purchased in an invoice.

 Attributes:
o int idNumber: Unique identifier for the item.
o String name: Item name.
o double price: Price per unit.
o int quantitySold: Quantity of the item sold.
 Methods:
o Constructor to initialize item data.
o Getters and setters for all attributes.
o toString(): Formats item details for display.

Implementation Details

Invoice Class Key Methods

1. addItems():
o Prompts the user to add items dynamically.
o Ensures the list doesn’t exceed 10 items.
o Provides feedback if the list is full.

Example:

java
Copy code
invoice.addItems();

2. calcDiscount():
o Calculates a 10% discount for totals exceeding 5000 ALL.
o Uses array iteration to sum item costs.
3. valueAddedTax():
o Computes 20% VAT on the total item cost.
4. toString():
o Provides a detailed invoice summary, including:
 Customer details.
 List of items.
 Total cost before and after applying VAT and discounts.
Exercise 3: Assembled computers
The objective is to design a system for managing a company's inventory of assembled computers. Each
computer's attributes and its components (CPU, RAM, Hard Disk, Motherboard) are modeled as
separate classes.

The requirements state that each Computer is composed of multiple components: CPU, RAM,
Hard Disk, and Motherboard. Each component is represented as a separate class with relevant
attributes and methods. Default constructors provide pre-configured objects, and parameterized
constructors allow for customization.

Class Design

1. Computer Class

Represents a complete assembled computer.

 Attributes:
o CPU cpu: Processor details.
o RAM ram: Memory details.
o HardDisk hardDisk: Storage details.
o Motherboard motherboard: Motherboard details.
o int creationYear: Year of assembly.
o double price: Price of the computer.
 Key Methods:
o Default and parameterized constructors for flexible initialization.
o Getters and setters for all attributes.
o toString(): Combines details of all components into a formatted string.

2. CPU Class

Represents the central processing unit.

 Attributes:
o int clockFrequency: Frequency in GHz.
o SetArchitecture setArchitecture: CPU architecture (enum: CISC or RISC).
o int typeBits: Processor type (32 or 64 bit).
o int numberRegisters: Number of registers.
o Manufacturer manufacturer: Manufacturer (enum: AMD, INTEL).
 Key Methods:
o Default and parameterized constructors for initialization.
o Getters and setters for modifying attributes.
o toString(): Displays CPU specifications in a readable format.
3. RAM Class

Represents the random access memory.

 Attributes:
o int size: Size in GB.
o Type type: RAM type (enum: DDR, DDR2, DDR3).
o String manufacturer: Manufacturer name.
 Key Methods:
o Default and parameterized constructors.
o Getters and setters.
o toString(): Formats RAM details for display.

4. HardDisk Class

Represents the hard disk.

 Attributes:
o int size: Storage capacity in GB.
o int rotationsMinute: Speed in RPM.
o String manufacturer: Manufacturer name.
 Key Methods:
o Default and parameterized constructors.
o Getters and setters.
o toString(): Outputs Hard Disk specifications.

5. Motherboard Class

Represents the motherboard.

 Attributes:
o String chipsetVersion: Version of the chipset.
o int usbPorts: Number of USB ports.
o int ramCapacity: Maximum supported RAM in GB.
o String manufacturer: Manufacturer name.
 Key Methods:
o Default and parameterized constructors.
o Getters and setters.
o toString(): Formats motherboard details for display.
Exercise 4: Estimation of constant e
To solve this exercise I imported the BigDecimal and BigInteger classes from java.math.
Then I designed a method to calculate the factorial since by definition:
1 1 1
e = 1+ + +…..+
1! 2! n!
Then by using a different method calculate e and with a different method print e.

Exercise 5: Some terms of Fibonacci sequence

Since the Fibonacci sequence uses the first term and second term to build the ongoing sequence I
use 3 variables of BigInteger to calculate the terms:
BigInteger first = BigInteger.ONE;
BigInteger second = BigInteger.ONE;
BigInteger current;
Then I determine the bounds since the requirements state that only numbers with n digits must be
printed . After using a Scanner object to get n, I determine the bounds as minimum: 10n−1 and
maximum: 10n . So if n=3 minimum is number is 100 (included) and maximum number is 1000
(not included). So by using a loop and a condition to check if the term is inbetween the minimum
and maximum print the term and generate a new term.
Exercise 6: DNA sequence operations
The exercise requires different operations:
1. Forming the complementary sequence
To create this method I use a object of StringBuilder and build a for each loop that
switches through cases (ex. Case: A append T) and also be careful for default
arguments . The method returns the complement of the initial String.

2. To find the most frequent base


I use a array of size 4 to represent each base (A, G, T, C)
Then using a for each loop switch the base and increment terms of the array.
Then using a for loop and a condition find the most frequent base and return it.
3. Insert and Remove
The insert method needs the initial and toInsert Strings and position while in the
Remove method the position is not needed. Using conditions if the position is
within scope in the Insert method and if the toRemove string exists we care about
optimization.
4. Decompress
Regular Characters: Appended directly to the result.
Digits Outside Parentheses: Repeat the last character accordingly.
Characters Inside Parentheses: Stored in a buffer until ) is encountered.
After ): The buffered sequence is repeated based on the next digit.
Returns the fully expanded DNA sequence.

You might also like