• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Create my own object that works like an array  RSS feed

 
Marshal
Posts: 13439
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Louis Müller wrote:Here is the task I want to solve:

A mail-order house sells five products whose retail prices are as follows:

product 1, $2.98;
product 2, $4.50;
product 3, $9.98;
product 4, $4.49;
product 5, $6.87.
Write an application that reads a series of pairs of numbers as follows: <product number> <quantity sold>. Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to stop looping when reading 0 as product number and display the final results.


I haven't read through the entire thread in detail but I can say this: A lot seems to have been said that didn't really apply to what is being asked for in original task description. Since the discussion afforded the OP a number of learning opportunities, I think it was still good in that way. However, this is still a prime example of over-engineering and gold-plating. We see this sort of thing happen all the time in the real world and it costs companies literally billions of dollars. Just keep that in mind as you go forward.

The task itself was very simple. Read in data until you find a sentinel value, then display totals. You are asked to use a switch statement to lookup the price of each product. To give you a point of comparison on what someone with a focus on getting things done would do, here's the code I would have written to just satisfy what is asked for in the problem. And even this solution goes a little bit above what is specifically asked.

Lines 4 to 27 make up a simple test harness to exercise the solution which is the SalesReport class.

You can try this code out for yourself here: https://repl.it/@jlacar/SalesReportWithTotals
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!