Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I am trying to understand how inheritance works and am working on a GroceryBill class. The goal of this program is to take in

Hello, I am trying to understand how inheritance works and am working on a GroceryBill class.

The goal of this program is to take in a text file (Items.txt) as a parameter for the GroceryBill constructor and take the text apart based on type (double, String, and int). I then need to work with the Items class to calculate the GroceryBill using methods such as getName(), getPrice, etc. Any help on this would be greately appreciated.

Items.txt

5 Apple "red_sweet_apple" .25 .05 1 Pizza "round_savory_food" 4.50 .35 1 Coffee "Keeps_me_awake" 4.99 .99 2 Microwave "ZapZap" 240.65 34.50

Item.java

class Item{

private double price; private double discount; private int quantity; private String title; private String desc; public Item(String name, double price, int quantity, double discount, String description){ this.price = price; this.discount = discount; this.title = name; this.desc = description; this.quantity = quantity; } public int getQuantity(){ return this.quantity; } public double getPrice(){ return this.price; } public double getDiscount(){ return this.discount; } public String getName(){ return this.title; } public String getDesc(){ return this.desc; } }

GroceryBill.java (So far)

import java.util.*; import java.io.*;

public class GroceryBill {

public GroceryBill() { Scanner x = new Scanner(System.in); int quant = 0; String title = ""; String pic = ""; double cost = 0.0; double off = 0.0; try { System.out.println("What is the name of the file? "); File file = new File(x.nextLine()); while (x.hasNextLine()) { quant = x.nextInt(); title = x.next(); pic = x.next(); cost = x.nextDouble(); off = x.nextDouble(); } x.close(); } catch (Exception ex) { System.out.println("Could not locate file..."); } }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of job analysis.

Answered: 1 week ago

Question

How do we do subnetting in IPv6?Explain with a suitable example.

Answered: 1 week ago

Question

Explain the guideline for job description.

Answered: 1 week ago

Question

What is job description ? State the uses of job description.

Answered: 1 week ago

Question

What are the objectives of job evaluation ?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago