Ryan Bury

Coffee House Application

CoffeeHouseApp Picture

Download Runnable Jar

* You need to unzip the file to run it.


Main.java

public class Main {
	public static void main(String[] args)
	{
		CoffeeHouse myMenu = new CoffeeHouse();
	}
}

This file only instantiates a new instance of the coffee house menu.


PricedItem.java

import java.text.DecimalFormat;

public class PricedItem {
	private final int desiredLength = 25;
	private String name;
	private double price;
	private static double totalPrice = 0;
	public PricedItem(String n, double d)
	{
		totalPrice += d;
		name = n;
		price = d;
	}
	
	public static double getTotalPrice()
	{
		return totalPrice;
	}
	
	public String createString(int length, char fill)
	{
		char[] arr = new char[length];
		for(int i = 0; i < length; i++)
		{
			arr[i]=fill;
		}
		return new String(arr);
	}
	
	public String toString()
	{
		if(name == "" && price == 0)
		{
			return createString(desiredLength, '-');
		}
		String str = "";
		int length1 = name.length();
		DecimalFormat dollarStructure = new DecimalFormat("$0.00");
		int length2 = dollarStructure.format(price).length();
		
		str = name + createString(desiredLength - length1 - length2, '.') + dollarStructure.format(price);
				
		return str;
	}
}

Here, the object PricedItem is defined. This is to simplify the process of creating an itemized receipt later in the program.


ImagePanel.java

import java.text.DecimalFormat;

public class PricedItem {
	private final int desiredLength = 25;
	private String name;
	private double price;
	private static double totalPrice = 0;
	public PricedItem(String n, double d)
	{
		totalPrice += d;
		name = n;
		price = d;
	}
	
	public static double getTotalPrice()
	{
		return totalPrice;
	}
	
	public String createString(int length, char fill)
	{
		char[] arr = new char[length];
		for(int i = 0; i < length; i++)
		{
			arr[i]=fill;
		}
		return new String(arr);
	}
	
	public String toString()
	{
		if(name == "" && price == 0)
		{
			return createString(desiredLength, '-');
		}
		String str = "";
		int length1 = name.length();
		DecimalFormat dollarStructure = new DecimalFormat("$0.00");
		int length2 = dollarStructure.format(price).length();
		
		str = name + createString(desiredLength - length1 - length2, '.') + dollarStructure.format(price);
				
		return str;
	}
}

The ImagePanel is simply a formality that Java requires in order to draw images easily in a GUI.


CoffeeHouse.java

Click to view full file

The CoffeeHouse part of the application is the main part of the application that creates the GUI, handles the action, and prints the receipt.