Quote
Department of Computer Science
CS 203 - Fall 2015 - Assignment
Assigned: 14 Oct 2015
Due Date: 14 Nov 2015
Write a simulation program of a customer buying ice cream from an ice cream parlor. An input file will be provided which contain the code and flavor of the ice cream. A database will contain the code number, price per ounce, and the flavor.
Create a class called PRODUCT with three instance variables which includes the string Code, string Flavor, and double Price. Include the correct constructor, use get and set methods, and overrides of class Object.
Create a class for the database which should contain an array which will store PRODUCT, which will be read from a file. This class will contain methods that will return the flavor and price from an item with a given code: string getFlavor(String code); double getPrice(String code);
The output of this program is to be a Jframe, which will be a separate GUI class. This will be a receipt for the customer. It should contain one per line of the following: name, flavor, ounces, and total cost of the line, and also the final total cost of all of the purchases.
My assignment requires me to use the text file with the list of database.
This is what is inside the textfile database (code, flavor, price)
1101,CHOCOLATE,1.00
1102,STRAWBERRY,1.25
1103,VANILLA,0.89
1104,PISTACHIO,1.50
This was what is in the transaction file, which I assume is the code + weight
1101,2.3
1102,2.99
1103,2.50
1104,325
This is what I have so far, but I'm stuck on how I should approach the text file scanning.
Code
import java.awt.GridLayout;
import javax.swing*;
public class IceCream{
public static void main(String[] args){
createAndShowGUI();
}
private static void createAndShowGUI(){
//Create and show the GUI.
JFrame frame = new JFrame("Receipt");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);
frame.setLocation(200,200);
frame.setLayout(new GridLayout(2,1));
JTextArea textArea = new JTextArea(5, 20);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
frame.getContentPane().add(scrollPane);
JLabel label = new JLabel("");
textArea.setText("");
frame.pack();
frame.setVisible(true);
readAndDisplayMatrix(frame, textArea, label);
}
public static void main (string[] args){
//Variables
private static class Receipt {
private string code;
private string flavor;
private float price;
public produceItem(String c, String n, float p){
this.code=code;
this.flavor=flavor;
this.price=price;
}
public string getCode(){
return this.code;
}
public string getflavor(){
return this.flavor;
}
public string getPrice(){
return this.price;
}
public void setCode(string code){
this.code=code;
}
public void setflavor(string flavor){
this.flavor=flavor;
}
public void getPrice(float price){
this.price=price;
}
public string getCode(){
return code;
}
public string getflavor(){
return flavor;
}
public float getPrice(){
return price;
}
}
}
This post was edited by Whalefood on Oct 25 2015 01:37pm