Warning

 

Close

Confirm Action

Are you sure you wish to do this?

Confirm Cancel
BCM
User Panel

Posted: 9/25/2005 12:38:24 PM EDT
I'm taking a JAVA programming class this semester, and I'm trying to straighten out a program I have written. I will post the code or IM it to anyone who thinks they can help. Thanks in advance!
Link Posted: 9/25/2005 12:39:17 PM EDT
[#1]
I'm game. Drop me an email or post it here.
Link Posted: 9/25/2005 12:43:10 PM EDT
[#2]
I am a coding god... please send it to me and your problems will be resolved.  [email protected]
Link Posted: 9/25/2005 12:45:12 PM EDT
[#3]
Here's the code. I know I'm doing something stupid, but I cant figure out what:
/*
Lab 2: Bill's Burgers
Programmer: J. Eyster
Date: September 21, 2005
Filename: BillsBurgers.java
Purpose:This program will generate the total cost of food order
       and calculate 7% sales tax.
*/

import java.io.*;
import java.awt.*;
import javax.swing.*;

public class BillsBurgers
{
public static void main (String[] args) throws IOException
{
String bill;
String taxamount;
double total;
double tax;
double totalplustax;


BufferedReader dataIn = new BufferedReader(new
InputStreamReader(System.in));

//prompt and get input
System.out.println("BILL'S BURGERS TAX AND TOTAL CALCULATOR");

System.out.println();
System.out.print("Enter total of order:");
total = dataIn.readLine();

//calculations
totalplustax = total*tax;

//output
System.out.println();
System.out.println("Your total with tax is"+ Math.round(totalplustax)+".");
System.out.println();


}
}


Link Posted: 9/25/2005 12:47:20 PM EDT
[#4]
Looks like you are never assigning a value to "tax"
Link Posted: 9/25/2005 12:49:08 PM EDT
[#5]
the value of tex is never assigned, when it goes to calculate it, it goes bezerk.
Link Posted: 9/25/2005 12:49:13 PM EDT
[#6]
Oh yeah, let me go back and take a look at that...
Link Posted: 9/25/2005 12:50:00 PM EDT
[#7]

Quoted:
Looks like you are never assigning a value to "tax"



Yep.
Link Posted: 9/25/2005 12:50:29 PM EDT
[#8]
What is your objective with the tax, you can either hardcode it, or have the customer insert it (doesn't make much sense).
Link Posted: 9/25/2005 12:53:04 PM EDT
[#9]
It's supposed to calculate 7% sales tax based on input from the user.
Link Posted: 9/25/2005 12:54:28 PM EDT
[#10]
BTW here's a little number I'm working on.... in C++ though.



//datedItems.def
//Written September 24, 2005
//Author: Peter xxxxxx
//A class representing a collection of pairs consisting of a
//      date and item objects

#include "datedItems.h"
#include <iostream>
using std::cout;
using std::endl;

//Constructor
//Initializes our datedItems object to an empty collection
template <class Etype>
DatedItems<Etype>::DatedItems() : vectorPairs(), listPairs()
{
//no code required in constructor
}

//addItem
//Parameters: Etype param1: a generic type object that we are attempting to add
//            Date param2:  a date object which we are attemping to add
//If both parameters are unique, and not found in our collection, we will add
//         this pair of of datedItems.
template<class Etype>
void DatedItems<Etype>::addItem(Etype param1, Date param2)
{
  bool found=false;
  vectorStart = vectorPairs.begin();
  vectorFinish = vectorPairs.end();
  collectStart = listPairs.begin();
  collectFinish = listPairs.end();
  pair <Etype, Date> pair1(param1,param2);
  vectorFound = findItem (vectorStart, vectorFinish, param2, dateIsEqual);
  while (vectorStart!=vectorFinish)
  {
    if ((!(vectorFound==vectorFinish)) || (vectorStart->first==param1))
    {
       Warn("addItem: parameters not unique!");
       found=true;
       vectorStart=vectorFinish;
    }
    else
    {
       vectorStart++;
    }
  }
  if (!found)
  {
     vectorPairs.push_back(pair1);
     DateGreater<Etype> dateIsGreater(param2);
     collectFound=findFirstSatisfier(collectStart, collectFinish, dateIsGreater
);
     listPairs.insert(collectFound,pair1);
  }
}
 
//redateItem
//Parameters:  date: old date object which we want to change
//             redate:  the date which we want to set to the object  
//Replaces a date of an item to another one should the old date be found
template <class Etype>
void DatedItems<Etype>::redateItem(Date date, Date redate)
{
  collectStart = listPairs.begin();
  collectFinish = listPairs.end();      
  collectFound = collectStart;

  collectFound = findItem(collectStart, collectFinish, date, dateIsEqual);
  if (collectFound==collectFinish)
  {
     Warn("redateItem: old date not in collection!");
     return;
  }
  collectFound = findItem(collectStart, collectFinish, redate, dateIsEqual);
  if (!(collectFound==collectFinish))
  {
     Warn("redateItem: new date already in collection!");
     return;
  }  
 

  vectorStart = vectorPairs.begin();
  vectorFinish = vectorPairs.end();
  vectorFound = findItem(vectorStart, vectorFinish, date, dateIsEqual);
  if (!(vectorFound==vectorFinish))
  {
     vectorFound->second=redate;
  }

  collectStart = listPairs.begin();
  collectFound = findItem(collectStart, collectFinish, date, dateIsEqual);
     
  pair<Etype, Date> pairTemp(collectFound->first, redate);
  listPairs.erase(collectFound);
  DateGreater<Etype> dateIsGreater(redate);
  collectFound = findFirstSatisfier(collectStart, collectFinish, dateIsGreater)
;
  listPairs.insert(collectFound, pairTemp);
}  
 

//retrieveItem
//Parameters: paramDate: date for the item we are attempting to retrieve
//Returns a generic item at a given date
//Seeks the current collection for the date given, and returns the item at the
//    date
template <class Etype>
Etype DatedItems<Etype>::retrieveItem(Date paramDate)

  vectorStart = vectorPairs.begin();
  vectorFinish = vectorPairs.end();
  vectorFound = findItem(vectorStart, vectorFinish, paramDate, dateIsEqual);
  if (vectorFound==vectorFinish)
  {
     Assert("retrieveItem: date does not exist in collection!");
  }
  else
  {
     return vectorFound->first;
  }

}

//retrieveDate
//Parameters: A generic item for which the collection will be searched
//Returns a date object at a given item
//Seeks the current collection for the given item and returns the date at that
//     given item
template <class Etype>
Date DatedItems<Etype>::retrieveDate(Etype param)
{
  vectorStart = vectorPairs.begin();
  vectorFinish = vectorPairs.end();
  while (vectorStart != vectorFinish)
  {
     if (param==vectorStart->first)
     {
        return vectorStart->second;
     }
     else
     {
        vectorStart++;
     }
  }  
  Assert("retrieveDate: item does not exist in collection!");

}
 
//numPairs
//This function simply returns the amount of datedItems in our collection
template <class Etype>
int DatedItems<Etype>::numPairs() const
{
  return vectorPairs.size();
}

//printShortDates
//This fucntion simply prints out the dates in a specific format in the order
//   which they were added
template <class Etype>
void DatedItems<Etype>::printShortDates()
{
  vectorStart = vectorPairs.begin();
  vectorFinish = vectorPairs.end();
  PrintDateWithSlashes<Etype> printSlashes;
  print(vectorStart, vectorFinish, printSlashes);

}

//printAll
//This function prints all the datedItems in chornological order
template <class Etype>
void DatedItems<Etype>::printAll()
{
  collectStart = listPairs.begin();
  collectFinish = listPairs.end();
  PrintDateWithMonthName<Etype> printMonthName;
  while (collectStart != collectFinish)
  {
     printMonthName(*collectStart);
     cout<<collectStart->first<<endl;
     collectStart++;
  }
}
Link Posted: 9/25/2005 12:55:01 PM EDT
[#11]
The indents are messed up....
Link Posted: 9/25/2005 12:55:18 PM EDT
[#12]
Other guys got it for you.

One suggestion: you're going to get more out of the class
if you go into it learning object-oriented programming.
What you wrote, while correct, is straight procedural code
much like standard C.
Link Posted: 9/25/2005 12:58:00 PM EDT
[#13]

Quoted:
The indents are messed up....



use the 'code' board tag.
Link Posted: 9/25/2005 12:58:24 PM EDT
[#14]

Quoted:
Other guys got it for you.

One suggestion: you're going to get more out of the class
if you go into it learning object-oriented programming.
What you wrote, while correct, is straight procedural code
much like standard C.



Object orientated programming is life for me now, aside from a few generic classes like the one I wrote above.
Link Posted: 9/25/2005 1:04:37 PM EDT
[#15]
Every time I compile, it tells me :
Incompatible types found: java.lang.string
What's up with that?
Link Posted: 9/25/2005 1:08:11 PM EDT
[#16]

Quoted:
Every time I compile, it tells me :
Incompatible types found: java.lang.string
What's up with that?



You need to parse the input as a double since it comes
in as a string. Look at the API for Double.parse(String)

eta:


try {
   total = Double.parseDouble(dataIn.readLine());
} catch (NumberFormatException nfx) {
   System.out.println("Input is not a number.");
   nfx.printStackTrace();
   System.exit(1);
}
Link Posted: 9/26/2005 8:34:50 AM EDT
[#17]
junebug68,
 Just as some advice, when you are debugging your code, print out values for variables. Had you done that, you would have figured out the problem yourself.
Close Join Our Mail List to Stay Up To Date! Win a FREE Membership!

Sign up for the ARFCOM weekly newsletter and be entered to win a free ARFCOM membership. One new winner* is announced every week!

You will receive an email every Friday morning featuring the latest chatter from the hottest topics, breaking news surrounding legislation, as well as exclusive deals only available to ARFCOM email subscribers.


By signing up you agree to our User Agreement. *Must have a registered ARFCOM account to win.
Top Top