d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Assistance For My Java Assignment > Paying 1,000 Fg
Prev123Next
Add Reply New Topic New Poll
Member
Posts: 54,832
Joined: Jan 10 2009
Gold: 1,992.00
Oct 24 2015 11:58pm
If no one can do a skype session to help me out, I guess I'll pay another amount for helping me out.

I have to make a program for a frozen yogurt shop.

I have to create a class with 2 strings and a double. The strings are for the code of each flavor and the other string is the name of each flavor. The double is the prices for the flavor and how much per oz.

I also need to make a database which contains the code, flavor, and prize which I get from a get and set method.

After that, I need to be able to print out a receipt through a JFrame.

I don't want the answers, but how should I start this?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 25 2015 12:19am
Quote (Whalefood @ Oct 25 2015 01:58am)
If no one can do a skype session to help me out, I guess I'll pay another amount for helping me out.

I have to make a program for a frozen yogurt shop.

I have to create a class with 2 strings and a double. The strings are for the code of each flavor and the other string is the name of each flavor. The double is the prices for the flavor and how much per oz.

I also need to make a database which contains the code, flavor, and prize which I get from a get and set method.

After that, I need to be able to print out a receipt through a JFrame.

I don't want the answers, but how should I start this?


what do you mean make a database? just some arraylist in memory? or are you using sqlite / mysql / etc?

I think the best place to start is where you have the most explicit requirements:
Quote
I have to create a class with 2 strings and a double.

So create a class with 2 strings and a double, and name them appropriately for what you use them for.
Member
Posts: 54,832
Joined: Jan 10 2009
Gold: 1,992.00
Oct 25 2015 12:21am
Quote (carteblanche @ Oct 25 2015 01:19am)
what do you mean make a database? just some arraylist in memory? or are you using sqlite / mysql / etc?

I think the best place to start is where you have the most explicit requirements:

So create a class with 2 strings and a double, and name them appropriately for what you use them for.


It's just a separate text file with a list with price, flavor, and code separated by commas.

I'm trying to work on this on my own, but I'm not sure how I use the 2 text files in my program to get the price and the flavors.

This post was edited by Whalefood on Oct 25 2015 12:34am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 25 2015 12:38am
Quote (Whalefood @ Oct 25 2015 02:21am)
It's just a separate text file with a list with price, flavor, and code separated by commas.

I'm trying to work on this on my own, but I'm not sure how I use the 2 text files in my program to get the price and the flavors.


if you design it well, you should be able to write the app first without using text files. just hard code a few prices / flavours so you can get all the business logic done for calculating total cost, printing receipt, etc. after the rest is done, you can insert your read-from-text-file logic.

before you write your code, start with some brain storming. what classes are involved and what are their responsibilities? take a guess at what methods you'll have.

This post was edited by carteblanche on Oct 25 2015 12:41am
Member
Posts: 29,367
Joined: Mar 27 2008
Gold: 504.69
Oct 25 2015 08:30am
Quote (Whalefood @ Oct 25 2015 02:21am)
It's just a separate text file with a list with price, flavor, and code separated by commas.

I'm trying to work on this on my own, but I'm not sure how I use the 2 text files in my program to get the price and the flavors.


You will need to use scanner but except from reading from the keyboard, you will read from your text files.
Member
Posts: 54,832
Joined: Jan 10 2009
Gold: 1,992.00
Oct 25 2015 01:35pm
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
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 25 2015 01:40pm
as i suggested earlier, start out without worrying about the text file. Put all that data in memory and proceed with your code.

and why do you have a private class inside of your main method?
Member
Posts: 54,832
Joined: Jan 10 2009
Gold: 1,992.00
Oct 25 2015 04:32pm
How do I separate and import certain parts of a line into an array?

The name, code, and price are separated by commas in a textfile.

I want to be able to store in an array in accordance to prive and code.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 25 2015 04:54pm
Quote (Whalefood @ Oct 25 2015 06:32pm)
How do I separate and import certain parts of a line into an array?

The name, code, and price are separated by commas in a textfile.

I want to be able to store in an array in accordance to prive and code.


http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)
Member
Posts: 54,832
Joined: Jan 10 2009
Gold: 1,992.00
Oct 25 2015 10:46pm
Is this the correct way of reading the text file?


Code
List<Produce> list = new ArrayList<Produce>() {
try (BufferedReader br = new BufferedReader(new FileReader("database.txt"))); {
String line;
while ((line = br.readLine()) != null) {
String[] items = line.split(",");
Row row = new Row();
row.setCode(row[0]);
row.setFlavor(row[1]);
row.setPrice(row[2]);
InfoList.add(row);
}
}
}
Go Back To Programming & Development Topic List
Prev123Next
Add Reply New Topic New Poll