-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode 26.txt
405 lines (283 loc) · 10.8 KB
/
code 26.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
1. Write an application that asks a user to enter an integer. Display a statement that
indicates whether the integer is even or odd. Save the file as EvenOdd.java.
Start
Read value
If (value % 2 == 0)
Print Even
Else
Print Odd
End if
End
2. Write an application that asks a user to enter three integers. Display them in
ascending and descending order. Save the file as AscendingAndDescending.java.
n1 n2 n3
3 1 2
1 3 2
1 2 3
Start
1. Read n1, n2, n3
2. high = -1
3. if (n1 > high)
high = n1
else
if (n2 > high)
high = n2
else
if (n3 > high)
high = n3
4. high2 = -1
5. if (
2 1 4
high1 = 10
if (n1 < high1)
high1 = n1
if (n2 < high1)
high1 = n2
if (n3 < high1)
high1 = n3
high2
high3
Start
Read n1, n2, n3
If (n1 > n2)
temp = n1
n1 = n2
n2 = temp
If (n2 > n3)
temp = n2
n2 = n3
n3 = temp
3.
a. Write an application for the Summerdale Condo Sales office; the program determines
the price of a condominium. Ask the user to choose 1 for park view, 2 for
golf course view, or 3 for lake view. The output is the name of the chosen view as
well as the price of the condo. Park view condos are $150,000, condos with golf
course views are $170,000, and condos with lake views are $210,000. If the user
enters an invalid code, set the price to 0. Save the file as CondoSales.java.
Start
Print "Choose 1 for PV, 2 for GCV, 3 LV"
Read choice (integer)
switch choice
case 1:
ChosenView = "PV"
Price = 150000
case 2:
ChosenView = "GCV"
Price = 170000
case 3:
ChosenView = "LV"
Price = 210000
default:
ChosenView = "None"
Price = 0
Print ChosenView, Price
End
b. Add a prompt to the CondoSales application to ask the user to specify a (1) garage
or a (2) parking space, but only if the view selection is valid. Add $5,000 to the
price of any condo with a garage. If the parking value is invalid, display an
appropriate message and assume that the price is for a condo with no garage.
Save the file as CondoSales2.java.
Start
Print "Choose 1 for PV, 2 for GCV, 3 LV"
Read choice (integer)
switch choice
case 1:
ChosenView = "PV"
Price = 150000
case 2:
ChosenView = "GCV"
Price = 170000
case 3:
ChosenView = "LV"
Price = 210000
default:
ChosenView = "None"
Price = 0
Print ChosenView, Price
if (((choice == 1) || (choice == 2) || (choice == 3))
Print "1 for Garage or 2 for Parking space"
Read CarExtra
switch CarExtra
case 1:
NewPrice = Price + 5000
Print NewPrice
case 2:
NewPrice = Price
Print NewPrice
default:
Print "nothing"
End
If ((choice == 1) || (choice == 2) || (choice == 3)) && (CarExtra == 1)
NewPrice = Price + 5000
Print NewPrice
If ((choice == 1) || (choice == 2) || (choice == 3)) && (CarExtra == 2)
NewPrice = Price
Print NewPrice
If ((choice == 1) || (choice == 2) || (choice == 3)) && ((CarExtra != 1) || (CarExtra !=2)
Print "Condo with no Garage or Parking space"
End
4. Write a program for Horizon Phones, a provider of cellular phone service.
Prompt a user for maximum monthly values
for talk minutes used,
text messages sent, and
gigabytes of data used,
and then recommend the best plan for the customer’s needs.
A customer who needs fewer than 500 minutes of talk and no text or data should
accept Plan A at $49 per month.
A customer who needs fewer than 500 minutes of talk and any text messages should
accept Plan B at $55 per month.
A customer who needs 500 or more minutes of talk and no data should accept either
Plan C for up to 100 text messages at $61 per month
or Plan D for 100 text messages or more at $70 per month.
A customer who needs any data should
accept Plan E for up to 2 gigabytes at $79
or Plan F for 2 gigabytes or more at $87.
Save the file as CellPhoneService.java.
Start
Read TMU, TMS, GB
If ((TMU < 500) && (TMS == 0) && (GB == 0))
Print "Plan A"
If ((TMU < 500) && (TMS > 0))
Print "Plan B"
If ((TMU >= 500) && (GB == 0))
Print "Plan C"
If ((TMU >= 500) && (TMS <= 100) && (GB == 0))
Print "Plan D"
If (GB < 2)
Print "Plan E"
Else
Print "Plan F"
5. a. Write an application that prompts a user for a month, day, and year. Display a
message that specifies whether the entered date is (1) not this year, (2) in an earlier
month this year, (3) in a later month this year, or (4) this month. Save the file as
PastPresentFuture.java.
b. Use the Web to learn how to use the LocalDate Boolean methods isBefore(),
isAfter(), and equals(). Use your knowledge to write a program that prompts a
user for a month, day, and year, and then displays a message specifying whether
the entered day is in the past, the current date, or in the future. Save the file as
PastPresentFuture2.java.
6. Barnhill Fastener Company runs a small factory. The company employs workers who
are paid one of three hourly rates depending on skill level:
Skill Level Hourly Pay Rate ($)
1 17.00
2 20.00
3 22.00
Each factory worker might work any number of hours per week; any hours over 40
are paid at one and one-half times the usual rate.
In addition, workers in skill levels 2 and 3 can elect the following insurance options:
Option Explanation Weekly Cost to Employee ($)
1 Medical insurance 32.50
2 Dental insurance 20.00
3 Long-term disability insurance 10.00
Also, workers in skill level 3 can elect to participate in the retirement plan at 3% of
their gross pay.
Write an interactive Java payroll application that calculates the net pay for a factory
worker. The program prompts the user for skill level and hours worked, as well as
appropriate insurance and retirement options for the employee’s skill level category.
The application displays:
(1) the hours worked,
(2) the hourly pay rate,
(3) the regular pay for 40 hours,
(4) the overtime pay,
(5) the total of regular and overtime pay, and
(6) the total itemized deductions. If the deductions exceed the gross pay, display an
error message; otherwise, calculate and display
(7) the net pay after all the deductions have been subtracted from the gross.
Save the file as Pay.java.
Start
1. Read hours
2. Read skill
3. if (skill == 1)
payrate = 17
else
if (skill == 2)
payrate = 20
else
payrate = 22
4. if (hours > 40)
regularpay = 40 * payrate
overtimepay = (hours - 40) * payrate * 1.5
else
regularpay = hours * payrate
5. totalpay = regularpay + overtimepay
//suppose to be here
7. Print hours
8. Print payrate
9. Print regularpay
10. Print overtimepay
11. Print totalpay
//~~~~~~~~~~~~~~~~~~~~~~~~~~
6. if ((skill == 2) || (skill == 3))
Print (1 Medical, 2 Dental, 3, Disability)
Read insuranceoption
if (insuranceoption == 1)
insurance = "Medical"
insuranceamount = 32.50
// dont do this newtotalpay = totalpay - insuranceamount
if (insuranceoption == 2)
insurance = "Dental"
insuranceamount = 20
// dont do this newtotalpay = totalpay - insuranceamount
if (insuranceoption == 3)
insurance = "Disability"
insuranceamount = 10
// dont do this newtotalpay = totalpay - insuranceamount
if (skill == 3)
Print "Would you like a retirement plan"
Read rpchoice
if (rpchoice = "y")
rp = totalpay * 0.03
deductions = insuranceamount + rp
if (deductions > totalpay)
Print "Error Message"
else
newtotalpay = totalpay - deductions
// should only print these if that thing never exceed
12. Print insurance, insuranceamount
13. Print rp
14. Print deductions
15. Print newtotalpay
//done elswhere
//7. Print hours
//8. Print payrate
//9. Print regularpay
//10. Print overtimepay
//11. Print totalpay
//12. Print insurance, insuranceamount
//13. Print rp
//14. Print deductions
//15. Print newtotalpay
End
7. Create a class that holds data about a job applicant. Include a name, a phone number,
and four Boolean fields that represent whether the applicant is skilled in each of the
following areas: word processing, spreadsheets, databases, and graphics. Include a
constructor that accepts values for each of the fields. Also include a get method for
each field. Create an application that instantiates several job applicant objects and
pass each in turn to a Boolean method that determines whether each applicant is
qualified for an interview. Then, in the main() method, display an appropriate
method for each applicant. A qualified applicant has at least three of the four skills.
Save the files as JobApplicant.java and TestJobApplicants.java.
8. Create an Automobile class for a dealership. Include fields for an ID number, make,
model, color, year, and miles per gallon. Include get and set methods for each field.
Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not
allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do
not allow the miles per gallon to be less than 10 or more than 60; if it is, set the miles
per gallon to 0. Include a constructor that accepts arguments for each field value and
uses the set methods to assign the values. Write an application that declares several
Automobile objects and demonstrates that all the methods work correctly. Save the
files as Automobile.java and TestAutomobiles.java.
9. Create a class named Apartment that holds an apartment number, number of
bedrooms, number of baths, and rent amount. Create a constructor that accepts
values for each data field. Also create a get method for each field. Write an
application that creates at least five Apartment objects. Then prompt a user to enter
a minimum number of bedrooms required, a minimum number of baths required,
and a maximum rent the user is willing to pay. Display data for all the Apartment
objects that meet the user’s criteria or an appropriate message if no such apartments
are available. Save the files as Apartment.java and TestApartments.java.
10. Use the Web to locate the lyrics to the traditional song “The Twelve Days of
Christmas.” The song contains a list of gifts received for the holiday. The list is
cumulative so that as each “day” passes, a new verse contains all the words of the
previous verse, plus a new item. Write an application that displays the words to the
song starting with any day the user enters. (Hint: Use a switch statement with cases
in descending day order and without any break statements so that the lyrics for any
day repeat all the lyrics for previous days.) Save the file as TwelveDays.java.