Given the following Queue and Handphone ADTs answer the questions below : public class Queue { public Queue() {... } public void enqueue(Object elem){...} public Object dequeue() {...} public boolean isEmpty(){...} //definition for other methods } public class Handphone{ //declaration of data public Handphone(String sn, String brand, double price){...} public String getSN(){....} public String getBrand(){...} public double getPrice(){...} public String toString(){...} //to display output } ATOZ Telecommunications Sdn. Bhd. is a company that sells handphones and currently having promotions on 10 brand new sophisticated handphones. Assuming that all their handphones are stored in a queue, the first 8 customers purchase the handphone will be given a discount of 25% off. One customer is only limited to purchase one handphone.So, we can see requirement of Queue Class and Handphone Class. For this, I implement my LinkedList class to make Queue. This also require Node class.
a) Create a Queue object named as qHandphone.
b) Input TEN(10) handphone objects and store them into qHandphone.
c) Display the output for all handphone objects using the following example:
SERIAL NUMBER BRAND NORMAL PRICE DISCOUNTED PRICE
1234 NOKIA 1200.50 900.375
1235SAMSUNG1234.67 926.0025
1236 SONY 860.87 645.6525
1237 BLACKBERRY 1345.30 1008.975
1238 NOKIA 985.45 739.0875
1239 NOKIA 744.40 558.3
1240 BLACKBERRY 750.00 562.50
1241 NOKIA 977.70 733.275
1242 APPLE 1668.98 1668.98
1243 NOKIA 666.60 666.60
d) Calculate and display the total prices for the handphones sold by the company.
This is my Queue class. I didn't make method isEmpty() because already have it in my LinkedList class. I make Queue the subclass of LinkedList.
Then I create Handphone class. Although, I didn't implement my toString() method in my application later for the sake of formatting.
Now, I still not so sure about "One customer is only limited to purchase one handphone.". I think it is just a policy so the company not getting bankrupt. Imagine, the promotion for first 8 customers, but if the first customers buy 10 handphone?
Now, let's tackle and solve this problem. First, Input 10 handphone objects. We need to create a Queue variable of qHandphone. Then, we get inputs from user, 10 of handphone, and temporarily store in a Handphone object(in my case, its name is hp). Insert this into qHandphone.
Then, there are display part. looking further, we can see need to count discounted price and total price. so take it in mind to do it at the same time. Also, we want to use a counter to calculate 8 of customers, because only first 8 customers get discount.
If you notice, I use printf. there are some explanation in the links I put in documentation of the source. But if you already know about printf, yeah, it is very similar to C++ printf. This allow for formatting, but, only to your output/display stream. While using String.format() will actually format the string and can be stored as such. I don't need to store, so why bother? Simpler, efficient. We are software engineer. :D
No comments:
Post a Comment