Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started