Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Trying to complete a store register program for school. HELP!

Posted on 2009-04-13
1
211 Views
Last Modified: 2013-11-23
I don't know where to start.  I don't think I'm understanding what I need to do and why to make this program work.  

Right now I'm trying to get a proper return value for the receipt but for some reason it's just giving me random letters and numbers as output.  I can't figure out why.  Can someone give me some insight as to where I'm going wrong and what direction I need to go.  

Directions:
Implement a program to run at a checkout counter in a store.  The main method will create the CheckOut object and then give it a number of Items to check out.  The CheckOut object will be able to produce an itemized receipt. (Hint: You can use an ArrayList or a String to build the receipt as items are sold.)
Then it shows a partial class diagram
CheckOutMain
+void main(...)

Item
-String descr
-double price

CheckOut
-double totalSale
-double receipt

+CheckOut(double taxRate)
+void sell (Item anItem)
+double getTotalSale()
+double getTaxes()
+String getReceipt()

This is what I have so far and have no idea on knowing what I'm doing wrong.

Thanks.
public class CheckOut 
{
	public double totalSale;
	public String receipt;
	public double rate;
		
	CheckOut()
 	{
	    totalSale = 0.00;
	    receipt = "";
		rate = .06;
	}
 
	CheckOut(double totalSale, String receipt)
	{
	    this.totalSale = totalSale;
		this.receipt = receipt;
	}	
	
    public double getTotalSale()
    {
	    return totalSale;
    }
    
    public String getReceipt()
    {
    	return receipt;
    }
 
	public void sell(Item anItem)
	{
		System.out.println( ": " + anItem);
	}    
	
	public void getTaxes(double rate)
	{
		totalSale = totalSale + (rate * totalSale);
	}
}
 
 
public class Item extends CheckOut
{
	public String desc;
	public double price;
	
	public Item(String desc, double price)
	{
		super();
		this.desc = desc;
		this.price = price;		
	}
 
 
	
	public String getDesc()
	{
		return desc;
	}	
	
	public double getPrice()
	{
		return price;
	}
}    
 
 
 
 
public class CheckOutMain 
{
public static void main(String[] args)
	{
		CheckOut cust1 = new CheckOut();
		Item coat = new Item("coat", 53.45);
		cust1.sell(coat);
		Item hat = new Item("baseball cap", 19.95);
		cust1.sell(hat);
	}
}

Open in new window

0
Comment
Question by:etan08
1 Comment
 
LVL 16

Accepted Solution

by:
ai_ja_nai earned 500 total points
ID: 24133034
First of all, this is conceptually wrong:

public void sell(Item anItem)
        {
                System.out.println( ": " + anItem);
        }  

anItem can't be printed like a string, you should put anItem.getDesc()

Second, why Item extends CheckOut??? They have nothing in common! Why Item should override abstract methods (and it doesn't) in CheckOut? It's wrong.

Third, you don't have a vision over the project: a checkout is an aggregation of Item instances. It should have, therefore, an ArrayList<Item> parameter called "basked". When you invoke the method sell, you add that Item to the basket. When you are tired, you invoke the method getTotalSale and sum the price of all Items contained in the basket....

I belive it's all you have to do. An advice for the future: when you are stuck during the requisite analysis ask yourself "what should do this program?"
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 35
by zero exception 10 52
jboss 7.1 start up error 1 31
running on tomcat not jboss eap 7.0 3 18
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question