0 Replies - 1174 Views - Last Post: 16 November 2009 - 06:49 PM Rate Topic: -----

#1 The Hobo Programer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-November 09

Having problem with "cash register " Program

Post icon  Posted 16 November 2009 - 06:49 PM

Hello all,

First of let me say Hi. I just found this site which looks really good. I am currently taking programing and it is starting to get harder and I need some help. My teacher problem is defined as "

Write a cash register program that will ask the user to enter the name and unit price for each item purchased.

The program must error check for negative prices and for blank names.

To stop entering items the user will need to type stop for the item name.

Store the names and unit prices of the items in arrays.

Next the program needs to find the total before tax cost for the purchase.

Next the program needs to find the sales tax on the purchase. You can assume a tax rate of 5%.

Next the program needs to calculate the after tax cost.

Finally the program must produce a nicely formatted bill."

I am having a problem with the "ask the user to enter the name and unit price for each item purchased.

The program must error check for negative prices and for blank names.

To stop entering items the user will need to type stop for the item name.

Store the names and unit prices of the items in arrays."




My code:

  /*
		   asks the user for the name of each item
	   @param  itemName --> the array to store each items name
  
		   @return  numItem --> the number of items being purchased
  */
 

public static int getItemName(String[] itemName)  
{ 
 Scanner scanIn = new Scanner(System.in);					
  String setinal = "stop";					   // ends the loop for the items names
  boolean blank = true;						 // checks for the same name entered
  int numItem = 0;					// the number of items
  int itemNum = 0;							 // the current student name to be entered
  String item; 

do
{

 System.out.println("Enter items #" + (itemNum + 1) + "'s name"
				   + " Enter stop to quit.");   
  item = scanIn.nextLine(); 
  same =  itemName[numItem].equalsIgnoreCase("");
  getItems(blank);


} while (blank);

return numItem;
}

public static void getItems(boolean same)  
 {
  
   if (!same)
	 {
	   itemName[itemNum] = item;
	   itemNum++;
	 }

   if (same)
	 {  
	   System.out.println( "ERROR, you seem to be stupid and entered nothing for item number  " + itemNum + " I will reset and PLEASE enter a name or I will display the blue screen of death! >:)");
	  }
 }
  /*
		   asks the user for a student grade.
  
		   @param  numStudents -->  The number of students
	   @param  answerKey   -->  answers to the questions
	   @param  percentScore --> the scores of each student
	   @param  studentName -->  names of the students
		   @param  studentAnswer --> the students answer to each problem
  */
  
 public static int getPrice(int numItem,int[] itemPrice, String[] itemName )
  {
   
   boolean bad;   // true  if the numStudents < 0 or numStudents > 100
					 // false otherwise
   int itemNum5 = 0;				  
	Scanner scanIn = new Scanner(System.in);

   do
	{
	 System.out.println("Enter the price of  " + itemName[itemNum5] + ".");
	 itemPrice[itemNum5] = scanIn.nextInt();
	 
	 bad = (itemPrice[itemNum5] < 0);
	 
	 if (bad)
	 
		 System.out.println("\n\nERROR IN INPUT\nEnter a price less than -1................idiot\n\n");
		 
	}while (bad);
	
		 
  }// end getPrice








I know I have a few logic errors and I dont know how to fix them. If anyone can help that would be great.

Thank you :D

I almost forgot. This is not the complete program. This is only the section i am having difficulty with. Ignore the comments, I need to cahnge them. Oops!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1