Implement a fruit ordering system

Assignment Help Basic Computer Science
Reference no: EM131544466

Program Specifications

This program is to implement a fruit ordering system for an online supermarket. Customers will keep ordering the fruit of their choices and the system will compute the total cost per order until they decide to quit.

Its purpose is to illustrate the use of

  • Java classes
  • the this reference
  • Arrays of objects
  • Elementary Sorting
  • Binary search

Class Design

You need to have at least the following classes described below. Feel free to come up with more classes if needed.

class XYZ which contains only the main method (similar to assignment 5)

class OnlineSuperMarket

  • Private instance fields: an array of Fruit objects, a String for market name (Foothill Super Market for example), a String for web address (https://www.foothillmarket.com (Links to an external site.)
  • Links to an external site.
  •  for example).
  • Private constant static field: taxRate (initialized to 0.085)
  • Private constant static field for array size (initialized it to 10)
  • Constructors
  • Default constructor: allocate memory for the Fruit array and its default Fruit objects using the static field array size
  • Non-default constructor: takes two parameters for market name and web address (same name as the instance field names). Do the same array allocation as the default constructor. Must use the this reference.
  • Public instance methods:
  • accessor/mutator for market name and web address
  • init: declare a local String array and manually initialize it with fruit names of your choice. Use a loop to properly initialize the Fruit array instance field for each Fruit object (name, weight, and price where weight and price are randomly generated similar to assignment 4. You must set HI and LO for each Fruit differently as needed.
  • sort (take no parameter): sort the array of Fruit objects in ascending order by fruit Name. Must use one of the elementary sorting algorithms presented in class modules with some modification to fit the assignment. Library sort methods are not allowed
  • run (take no parameter): showing some advertising banner about online super market and web address, then using an infinite loop to start asking user to either order fruits or to quit. If user selects quit ("XXX") then invoke the quit method. If user selects Fruit Ordering ask user for fruit Name and weight. Invoke Find method with the input fruitName as parameter. If the Fruit is not found output an error message. If the Fruit is found invoke the order instance method of the found Fruit object. If the order method returns -1 (the requested purchase weight exceeds the Fruit's available weight) output an error message. Otherwise compute the total cost (with tax - use the static field taxRate) to show to the customer (Fruit:  Weight:   Price: Total (plus tax): ) and back to the menu again.
  • find (take a String as fruit Name): search for the fruit Name from Fruit array. The method returns a reference to the found Fruit object in the array or null if the Fruit is not found. Since the array of Fruit objects is sorted you must use binary search to locate the Fruit. Use the binary search algorithm in the class module with some modification to do the work.
  • quit(take no parameter) : display all Fruits (make sure you come up with the correct way to do this or you may encounter point deduction) and output a "Thanks for your visit and please come again." message then terminate the program
  • showFruits: display all fruits (implicitly use the toString method) must use the new for loop syntax

class Fruit

  • Private instance fields: a String for fruit name, a double for weight (in lbs), and a double for unit price
  • Constructors:
  • Default constructor: set fruit name to "?", set weight and unit price to 0.0
  • Non-default constructor: takes three parameters (same name as the instance field names) and properly initialize the instance fields using the this reference syntax.
  • Public instance methods:
  • accessor/mutator
  • order: take a double as fruit weight. If the requested purchase weight is more than what's currently available return -1. Otherwise update the weight instance field (purchase is approved now) then compute and return the cost of Fruit purchase (input weight * unit price)
  • toString: display fruit name, weight, and unit price in nice format (%5.2f or so etc ...)

Implementation Requirements

  • In main method
  • Declare an OnlineSuperMartket object reference and properly initialize it to NULL
  • Use new to allocate an OnlineSuperMartket object (using non-default constructor) and assign it to object reference above
  • Invoke init method
  • Invoke sort method
  • Invoke showFruits method
  • Invoke run

Sample Output

           // List of Fruits in sorted order by Fruit names with weight and price

                Your most convenient and time savings way to order fruit from

                                   FOOTHILL CS SUPER MARKET

                                   https://www.fh.cs.supermarket.com                            

                                    FRUIT ORDERING

                       Enter a fruit name or XXX to end: Apple

                       Enter weight in lbs: 2

                      You ordered:

                       Fruit: Apple

                       Weight in lbs: 2

                      Price:  $7.60 

                       Total cost (plus tax): $8.25

                      Enter a fruit name or XXX to end: XXX

                      // List of all Fruits

                      Thanks for your visit and please come again!!!

Testing (your output submission must sufficiently show the results of your testing)

  • Good path: order the first Fruit in the array, order the last Fruit, order a Fruit in the middle
  • Error path: order a Fruit that is not in the array, order a Fruit with requested weight higher than what's currently available
  • Extreme path: keep ordering the same Fruit until it's "out-of-stock" (i.e. weight==0) and no longer available for ordering

Reference no: EM131544466

Questions Cloud

Slpwireless and remote access security : SLP assignments for the course will build a security plan for a company or organization selected by the student.
List four benefits of using ntfs over fat32 : 1. List four benefits of using NTFS over FAT32 2. List five ways of hard drive hardening
Assignment on malicious software : This unit introduced you to malicious software. It divided malicious software into two broad categories: parasitic software, which are subprograms or fragments.
Motivation concepts theory : Motivation Concepts Theory - Define motivation, and provide a brief analysis of ways in which employees express motivation
Implement a fruit ordering system : This program is to implement a fruit ordering system for an online supermarket. Customers will keep ordering the fruit of their choices and the system.
What are some metrics or evaluation indicators : What are some metrics or evaluation indicators one should consider when evaluating the effectiveness of a new strategy in a healthcare organization?
Write an essay in which you explore the role of prejudice : Write an essay in which you consider Kurzel's decision to alter the play & what he gains or loses by interpreting and presenting the play in an unexpected way.
Comprehensive analysis and review : Explain a peer-to-peer network verses a client-server network. Because your system is strictly Windows, your document should concentrate.
Determine the effectiveness of the program : Please use this data to determine the effectiveness of the program by answering the following business questions:

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd