Ask Computer Engineering Expert

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 (http://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

                                   http://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

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92353189
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As