Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment: We will write a simulation of someone shopping in a grocery store fo

ID: 3765349 • Letter: A

Question

Assignment: We will write a simulation of someone shopping in a grocery store for produce (fruits and vegetables). An input file (read in using string tokenizer) will contain the code number and the weight of the item being purchased. A database will contain the code number, the name of the item (such as “Pineapple”) and the price per pound. Create a class called ProduceItem with three instance variables for the code (String), name (String) and price (float). Include appropriate constructors, get/set methods and overrides of class Object. Create a class for the database. It should contain an array which will store all the ProcudeItems (that will be read in from a file). This class should contain, among others, methods that will return the name and the price of an item with a given code: String getName(String code); float getPrice(String code); The output of the program should be a JFrame (a separate GUI class) that serves as a receipt for the customer. It should contain, one per line, the name, price, weight and total cost of each item, and at the end the total cost of all purchases. Submit the project through Blackboard by the due date for full credit. Note: that you will be uploading multiple files (i.e., the main application, the ProduceItem, the database, and the Receipt GUI.

Database File: (.txt)

4019,APPLES,0.99

4218,APRICOTS,3.49

4771,AVOCADOS,2.59

4011,BANANAS,.69

4045,CHERRIES,4.99

4263,DATES,3.99

4027,GRAPEFRUIT,1.09

4637,GRAPES,2.76

4053,LEMONS,3.45

4319,MELON,1.99

4377,NECTARINE,3.69

4012,ORANGES,2.49

4037,PEACHES,2.99

4026,PEARS,1.99

4029,PINEAPPLE,2.59

4041,PLUMS,3.49

Transaction File: 4012,4.03

4019,2.3 4011,1.72

4029,1.7 4027,2.37

4037,2.99 4637,2.01

4053,0.56 4319,5.65

4026,0.99 4041,0.49

Explanation / Answer

Hi,

Please find the below code for ProduceItem.java

package Cryptography;

class ProduceItem
{
    // instance variables - replace the example below with your own
    String code;
    String name;
    float price;
   

    /**
     * Constructor for objects of class ProduceItem
     */
    public ProduceItem()
    {
        code = "";
        name = "";
        price=0;
    }

   
    public void setCode(String code)
    {
        this.code=code;
    }
    public String getCode()
    {
        return(code);
    }
    public void setName(String name)
    {
        this.name=name;
    }
    public String getName()
    {
        return(name);
    }
    public void setPrice(float price)
    {
        this.price=price;
    }
    public float getPrice()
    {
        return(price);
    }
   
}

Find the code for Database.java. I have provided the logic for the functions.


package Cryptography;
import java.io.*;
import java.util.*;
public class Database
{

    public ProduceItem[] item_1;
   
   
    String getName(String code)
    {
     //return the name where ProduceItem code is same as input code
     return "";
    }
   
    float getPrice(String code)
    {
    //return the price where ProduceItem code is same as input code
    return(0);
    }
   
    public static void main(String[] args) throws FileNotFoundException {

    Scanner file_scan;
    String record;

    String code = "";
    String name = "";
    String price ="";

    file_scan = new Scanner(new File("database.txt"));
    while (file_scan.hasNextLine())
    {
        record = file_scan.nextLine();
        StringTokenizer data = new StringTokenizer(record, ",");

        while (data.hasMoreElements())
        {
           code = data.nextToken();
           name = data.nextToken();
           price = data.nextToken();
            System.out.println(code);
            System.out.println(name);
            System.out.println(price);
        }
    }

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote