469,923 Members | 1,777 Online

# java, algorithm problem

hello guys i have a bunsh of questions in java and algorithm
most of them i didnt have a problem in them but two i had a diffculty in them could u help me in them please coz its urgent .
the questions are:

Q1.DVD Sales and Shipping Algorithm Design:

You are to design an algorithm to calculate the total cost of a customer order for a number of DVDs. The total is comprised of a component for the DVDs, and also a shipping cost. The costs are determined as follows:
• DVDs cost \$19.95 each
• For every 4 DVDs chosen, the 5th one is free (so if the customer chooses
10 DVDs, they pay for 8 and get 2 free)
• The shipping cost is based on the following table:

Number of DVDs : Cost per item to Ship
1 to 4 DVDs : \$2.00 per DVD
5 to 8 DVDs : \$1.75 per DVD
9 to 13 DVDs : \$1.50 per DVD
14 or more : \$1.00 per DVD

Design an algorithm that will prompt an operator for the number of DVDs being
purchased. It is then to calculate the DVD charge as well as the shipping cost
based on the details above. The final total should then be displayed.

Q3. Train Ticket Algorithm Design:

You are to design an algorithm to run a train ticketing machine. The machine
operates by allowing a user to choose their desired ticket through a series of
menus. Based on the selections, the machine calculates a total, accepts money from the user, calculates any change owing and then allows the user to collect their ticket and change.

Below is the series of menus the user must choose from:

A. Child
C. Concession

A. Zone 1
B. Zone 2
C. Zone 1 and 2
D. Cancel

A. 2 hours
B. All Day
C. Cancel

The user will then be given the price and should then enter the amount being
tendered into the system, where the system will then calculate any change owing.
The price of a particular ticket depends on the selections. The description below
details the pricing:

• Child: Always free
• Adult: \$2.00 for a 2 hour ticket in only one zone. Add \$1.00 to travel both
zones. Add \$2.00 to travel all day.
• Concession: \$1.50 for a 2 hour ticket in only one zone. Add \$0.50 to travel
both zones. Add \$1.00 to travel all day

Note that the user can cancel during the process. This option takes them back to the beginning. Your program should also handle any invalid input from the user with the following message: “Invalid input – please re-enter choice”

thank you guys very much becouse i couldnt solve these two questions, but the rest of the questions easy except these two.
thanx
Mar 18 '07 #1
10 2137
sicarie
4,677 Expert Mod 4TB

We're more than happy to help, but we're here to help you learn it, which you won't do if you don't try. If you have tried, can you post the code or algorithm and any error messages you get?
Mar 18 '07 #2
r035198x
13,262 8TB
hello guys i have a bunsh of questions in java and algorithm
most of them i didnt have a problem in them but two i had a diffculty in them could u help me in them please coz its urgent .
the questions are:

Q1.DVD Sales and Shipping Algorithm Design:

You are to design an algorithm to calculate the total cost of a customer order for a number of DVDs. The total is comprised of a component for the DVDs, and also a shipping cost. The costs are determined as follows:
• DVDs cost \$19.95 each
• For every 4 DVDs chosen, the 5th one is free (so if the customer chooses
10 DVDs, they pay for 8 and get 2 free)
• The shipping cost is based on the following table:

Number of DVDs : Cost per item to Ship
1 to 4 DVDs : \$2.00 per DVD
5 to 8 DVDs : \$1.75 per DVD
9 to 13 DVDs : \$1.50 per DVD
14 or more : \$1.00 per DVD

Design an algorithm that will prompt an operator for the number of DVDs being
purchased. It is then to calculate the DVD charge as well as the shipping cost
based on the details above. The final total should then be displayed.

Q3. Train Ticket Algorithm Design:

You are to design an algorithm to run a train ticketing machine. The machine
operates by allowing a user to choose their desired ticket through a series of
menus. Based on the selections, the machine calculates a total, accepts money from the user, calculates any change owing and then allows the user to collect their ticket and change.

Below is the series of menus the user must choose from:

A. Child
C. Concession

A. Zone 1
B. Zone 2
C. Zone 1 and 2
D. Cancel

A. 2 hours
B. All Day
C. Cancel

The user will then be given the price and should then enter the amount being
tendered into the system, where the system will then calculate any change owing.
The price of a particular ticket depends on the selections. The description below
details the pricing:

• Child: Always free
• Adult: \$2.00 for a 2 hour ticket in only one zone. Add \$1.00 to travel both
zones. Add \$2.00 to travel all day.
• Concession: \$1.50 for a 2 hour ticket in only one zone. Add \$0.50 to travel
both zones. Add \$1.00 to travel all day

Note that the user can cancel during the process. This option takes them back to the beginning. Your program should also handle any invalid input from the user with the following message: “Invalid input – please re-enter choice”

thank you guys very much becouse i couldnt solve these two questions, but the rest of the questions easy except these two.
thanx
Mar 19 '07 #3
hello guys i didnt know the rules sorry
these are my answers tell me if there any mistakes
Q1.
Number of DVD's = X (char)
Shipment Cost = SmC
Promotion = Pro
Total Cost = TC DVD's Payment for
Final Total = FT

Began

Input X;
Pro= X/5;
Input DVD's payment for;
DVD's payment for= X-Pro
Input TC;
TC= DVD's payment for * 19.95
Input SmC;
If (X<=4)
SmC=2
If (X<9)
SmC=1.75
If (X<14)
SmC=1.50
Else
SmC=1.00
Input FT;
FT= TC*SmC;
EndIf
EndIf
EndIf
Display FT;
End
Mar 19 '07 #4
r035198x
13,262 8TB
hello guys i didnt know the rules sorry
these are my answers tell me if there any mistakes
Q1.
Number of DVD's = X (char)
Shipment Cost = SmC
Promotion = Pro
Total Cost = TC DVD's Payment for
Final Total = FT

Began

Input X;
Pro= X/5;
Input DVD's payment for;
DVD's payment for= X-Pro
Input TC;
TC= DVD's payment for * 19.95
Input SmC;
If (X<=4)
SmC=2
If (X<9)
SmC=1.75
If (X<14)
SmC=1.50
Else
SmC=1.00
Input FT;
FT= TC*SmC;
EndIf
EndIf
EndIf
Display FT;
End
Your variable names are confusing. Use more decriptive ones. Variable names should start with a small case letter e.g shipmentCost.

There is an operator called the modulo operator (%). Use it in your algorithm and post again
Mar 19 '07 #5
And
Q3.
Menu 2 = B: Zone Choice : Z1(Zone1), Z2(Zone2), Z12(Zone1&2), C1(Cancel)
Ticket Price = TP
Change Amount= Cg
Total Amount= TAmt

Output A;
Tell the user to choose from A; Cd,At,Cn;
If Input ! = Cd,At,Cn
Display "Invild CXhoice - please re-enter choice";
Get A;
Output B;
Tell the user to choose from A; Z1,Z2,Z12,C1;
Display"Invild choice - please re-enter choice";
Get B;
Else
Display A;
Output C;
Tell the user to choose fromC;Hr,AD,C2;
if input ! = Hr, AD,C2;
Display"Invild Choice - please re-enter choice";
Get C;
Else
Display A;
Mar 19 '07 #6
r035198x
13,262 8TB
And
Q3.
Menu 2 = B: Zone Choice : Z1(Zone1), Z2(Zone2), Z12(Zone1&2), C1(Cancel)
Ticket Price = TP
Change Amount= Cg
Total Amount= TAmt

Output A;
Tell the user to choose from A; Cd,At,Cn;
If Input ! = Cd,At,Cn
Display "Invild CXhoice - please re-enter choice";
Get A;
Output B;
Tell the user to choose from A; Z1,Z2,Z12,C1;
Display"Invild choice - please re-enter choice";
Get B;
Else
Display A;
Output C;
Tell the user to choose fromC;Hr,AD,C2;
if input ! = Hr, AD,C2;
Display"Invild Choice - please re-enter choice";
Get C;
Else
Display A;
One question at a time please.
Mar 19 '07 #7
hello but how to use the modulo operator ,please?
Mar 19 '07 #8
r035198x
13,262 8TB
hello but how to use the modulo operator ,please?
Surely you could have just looked it up in a text or something.

a % b returns the remainder when b is divided into a.
Mar 20 '07 #9
hello
i wish to ask you in general is Q1 answer correct or it considered wrong?

And for Q3 i did that is it correct or not?
Q3
Menu 2 = B: Zone Choice : Z1(Zone1), Z2(Zone2), Z12(Zone1&2), C1(Cancel)
Ticket Price = ticketPrice
Change Amount= changeAmount
Total Amount= totalAmount

Began

Output A;
Tell the user to choose from A; Cd,At,Cn;
If Input ! = Cd,At,Cn
Display "Invalid Choice - please re-enter choice";
Get A;
Output B;
Tell the user to choose from A; Z1,Z2,Z12,C1;
Display "Invalid Choice - please re-enter choice";
Get B;
Else
Display A;
Output C;
Tell the user to choose fromC;Hr,AD,C2;
if input ! = Hr, AD,C2;
Display "Invalid Choice - please re-enter choice";
Get C;
Else
Display A;
Input ticketPrice;
If A = Cd
Then ticketPrice = 0.00;
EndIf
Do
While A = At
If B = Z1 and C = Hr
Then ticketPrice = 2.00;
ElseIf B = Z2 and C = Hr
Then ticketPrice = 2.00;
Else
If B = Z12
Then ticketPrice = 3.00;
Else
Then ticketPrice = 4.00;
EndIf
EndIf
EndIf
EndIf
Do
While A = Cn
If B = Z1 and C = Hr
Then ticketPrice = 1.50;
Else
If B = Z2 and C = Hr
Then ticketPrice = 1.50;
Else
If B = Z12
Then ticketPrice = 2.00
Else
Then ticketPrice = 2.50
EndIf
EndIf
EndIf
EndIf
Display ticketPrice;
Tell user to enter ticketPrice;
Input changeAmount;
changeAmount = totalAmount – ticketPrice;
Display changeAmount;
If changeAmount > 0
Give out changeAmount;
EndIf
Print ticket;

End

thanks
Mar 20 '07 #10
r035198x
13,262 8TB
hello
i wish to ask you in general is Q1 answer correct or it considered wrong?

And for Q3 i did that is it correct or not?
Q3
Menu 2 = B: Zone Choice : Z1(Zone1), Z2(Zone2), Z12(Zone1&2), C1(Cancel)
Ticket Price = ticketPrice
Change Amount= changeAmount
Total Amount= totalAmount

Began

Output A;
Tell the user to choose from A; Cd,At,Cn;
If Input ! = Cd,At,Cn
Display "Invalid Choice - please re-enter choice";
Get A;
Output B;
Tell the user to choose from A; Z1,Z2,Z12,C1;
Display "Invalid Choice - please re-enter choice";
Get B;
Else
Display A;
Output C;
Tell the user to choose fromC;Hr,AD,C2;
if input ! = Hr, AD,C2;
Display "Invalid Choice - please re-enter choice";
Get C;
Else
Display A;
Input ticketPrice;
If A = Cd
Then ticketPrice = 0.00;
EndIf
Do
While A = At
If B = Z1 and C = Hr
Then ticketPrice = 2.00;
ElseIf B = Z2 and C = Hr
Then ticketPrice = 2.00;
Else
If B = Z12
Then ticketPrice = 3.00;
Else
Then ticketPrice = 4.00;
EndIf
EndIf
EndIf
EndIf
Do
While A = Cn
If B = Z1 and C = Hr
Then ticketPrice = 1.50;
Else
If B = Z2 and C = Hr
Then ticketPrice = 1.50;
Else
If B = Z12
Then ticketPrice = 2.00
Else
Then ticketPrice = 2.50
EndIf
EndIf
EndIf
EndIf
Display ticketPrice;
Tell user to enter ticketPrice;
Input changeAmount;
changeAmount = totalAmount – ticketPrice;
Display changeAmount;
If changeAmount > 0
Give out changeAmount;
EndIf
Print ticket;

End

thanks
Did you cater for the free DVD for every fifth one?
Mar 20 '07 #11