Question

In: Computer Science

Create a class tuck shop with following data members: String Owner String Food_Items[100] Double Price [100]...

  1. Create a class tuck shop with following data members:
  2. String Owner

    String Food_Items[100]

    Double Price [100]

    Int Quantity [100]

                   Note:

    • All arrays are open ended. It is not necessary that they are completely filled.
    • All three arrays will work in synchronization with each other i-e the item at index 0 will have its price in Price array at index 0 and quantity at index 0 of Quantity array.
  3. Methods:

    Two Constructors (default, four-argument)

    set for Owner , get for Owner

    display()

    addFooditem (?)                                       // Adds a food item, its price, and its quantity in the first available free slot in Food_Items, price and quantity array

    buy (?)                                                        //decrement quantity if more than one item is present. If only one item is present then the item should be removed from Food_Item array.

    compareTwoShops (   ? )                         //compare two shops and return the shop with more items.

    compareOwner (   ?    )                                 //compare owners of two shops and return true if both owners are           same and false otherwise.

    Note:

    Do not add data members at your own.

    Declare data as private

    Do not create set and get methods for array data members as they cannot be updated independent of each other.

    ‘?’ means that you need to identify the arguments if they are required.

    Runner:

    In the runner create two objects and all the above function.

  4. in java or in C#

Solutions

Expert Solution

package inter;

public class TuckShop {
        private String owner;
        private String food_items[];
        private double price[];
        private int quantity[];
        int i=0;
        public TuckShop(String owner, String[] food_items, double[] price, int[] quantity) {
                this.owner = owner;
                this.food_items = food_items;
                this.price = price;
                this.quantity = quantity;
        }
        
        public void display()
        {
                System.out.println(getOwner());
        }
        
        public void addFoodItem(String food_item,double pr,int quant)
        {
                i++;
                food_items[i]=food_item;
                price[i]=pr;
                quantity[i]=quant;
        }
        
        public void addFoodItem(String food_item)
        {
                for(int j=0;j<food_items.length;j++)
                {
                        if(food_items[j].equals(food_item))
                        {
                                if(quantity[j]>1)
                                {
                                        quantity[j]--;
                                }
                                else
                                {
                                        System.out.println("Not available");
                                }
                        }
                }
                
        }
        
        public int compareShop(TuckShop tuckshop2)
        {
                return this.food_items.length-tuckshop2.food_items.length;
        }
        
        public boolean compareOwner(TuckShop tuckshop2)
        {
                return this.getOwner().equals(tuckshop2.getOwner());
        }
        
        public String getOwner() {
                return owner;
        }
        
        public void setOwner(String owner) {
                this.owner = owner;
        }
}

Related Solutions

Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
Create a class called Car (Car.java). It should have the following private data members: • String...
Create a class called Car (Car.java). It should have the following private data members: • String make • String model • int year Provide the following methods: • default constructor (set make and model to an empty string, and set year to 0) • non-default constructor Car(String make, String model, int year) • getters and setters for the three data members • method print() prints the Car object’s information, formatted as follows: Make: Toyota Model: 4Runner Year: 2010 public class...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create getter/setter methods for all data types Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the book object that is formatted nicely and contains all information (attributes) In the main class: Create a main method that throws FileNotFoundException Import java.io libraries Import java.util.Scanner Create a loop to read...
Create a class called Sphere. The class will contain the following    Instance data double radius...
Create a class called Sphere. The class will contain the following    Instance data double radius Methods Constructor with one parameter which will be used to set the radius instance data Getter and Setter for radius             Area - calculate the area of the sphere (4 * PI * radius * radius)             Volume - calculate and return the volume of the sphere (4/3 * PIE * radius * radius * radius) toString - returns a string with the...
Create a class called Dishwash with a double called CubicFeet, a string called color, and a...
Create a class called Dishwash with a double called CubicFeet, a string called color, and a method called Washing. The Washing method should return a string to the main class with the text "Now washing dishes!" In the main class create an array of DishWasher size 3. Give each DishWasher a different color and CubicFeet. Use a foreach loop to display that info, call the Washing method, and display the text returned from the Washing method call. c#
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String Bread - of type String Price - of type Double Include get and set methods for these fields. The methods should be prefixed with 'get' or 'set' respectively, followed by the field name using camel case. For example, setMainIngredient. Use the application named TestSandwich that instantiates one Sandwich object and demonstrates the use of the set and get methods to test your class. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------...
Base Class class TransportationLink { protected: string _name; double _distance; public: TransportationLink(const string &name, double distance);...
Base Class class TransportationLink { protected: string _name; double _distance; public: TransportationLink(const string &name, double distance); const string & getName() const; double getDistance() const; void setDistance(double); // Passes in the departure time (as minute) and returns arrival time (as minute) // For example: // 8 am will be passed in as 480 minutes (8 * 60) // 2:30 pm will be passed in as 870 minutes (14.5 * 60) virtual unsigned computeArrivalTime(unsigned minute) const = 0; }; #endif Derived Classes...
Assignment: Create data file consisting of integer, double or String values. Create unique Java application to...
Assignment: Create data file consisting of integer, double or String values. Create unique Java application to read all data from the file echoing the data to standard output. After all data has been read, display how many data were read. For example, if 10 integers were read, the application should display all 10 integers and at the end of the output, print "10 data values were read" My issue is displaying how many integers were read and how many strings...
Create a struct for the following groups of data: (a) Product Data with the following members...
Create a struct for the following groups of data: (a) Product Data with the following members • ID • Name • Price • Quantity (b) Customer Data with the following members • ID • Name • Address • E-mail (c) Sales Data with the following members • Customer ID • Product IDs • Sale amount • Choose the types that you think will work best for the above descriptions. • Names should have a maximum size of 50. • Physical...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT