Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cost and discount not being calculated correctly  RSS feed

 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a problem with my output. Every time I run my program it’s not giving me the right output. This is what I have so far:

The first error is: every time I try to multiply the cost of the item times the items sold (`cost * sold`) it’s not doing anything.
Second: it’s just returning the cost of the item: `cost`.

Third: the discount is not even applying (I don’t know why). What I want to know is what exactly needs to be changed to get the program to operate properly. I’ve done multiple tests and changes and I am still in the same spot as before.
 
Norm Radder
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it’s not doing anything.

Can you post the program output that shows what you are talking about?  Add some comments to the incorrect output and show what you want the output to be.
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to get the program to run in NetBeans but, the issue with it is that it states there is no class found. What I want the output to do is keep track of sales items and to displaySales displays, the number sold the total sales, and total discount
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class ItemSalesDemo
{
public static void main(String[] args)
{
    ItemSales sale = new ItemSales(4, 10, 2.50);
    sale.registerSale(10);
    sale.displaySales();
}
}
Heres a demo.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heres a demo.


Sorry, I don't see the output or your comments about it.

Can you post the program output that shows what you are talking about?  Add some comments to the incorrect output and show what you want the output to be.


it states there is no class found

Please copy the full text of the error message and paste it here. It has important info about the error.
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://prntscr.com/fslgf5
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please copy the programs output and paste it here with your comments about what is wrong with it.

I don't follow links to other unknown sites.
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah okay I don't know how to go about posting the programs output right now I am still trying to fix where it would make it an actual class.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fix where it would make it an actual class.

Can you explain what the problem is?  Copy the full text of any error messages and paste them here.
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I would go running the program a box pops up that states there is no class found in the project I am trying to figure out what I need to do to get the program to function properly.
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The link I posted was a screenshot of the prompt popping up I don't know another way to show it other than that.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so the problem you are having is with the IDE you are using, not a problem with a java program.
I don't know anything about netbeans and can't help you.
It's confusing because the title of this post implies that the program is executing and not producing the correct output.

Have you tried compiling and executing the program in a command prompt window?
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I have not I'll give that a shot.
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error: Main method not found in class ItemSale, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application found a java complier and it read me this.
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your main() is in ItemSalesDemo, not ItemSales.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Corey Johnson wrote:I tried to get the program to run in NetBeans but, the issue with it is that it states there is no class found. . . .
We often recommend beginners not to use IDEs such as NetBeans because the “learning curve” for IDEs is too much to cope with when you are also trying to learn programming. It is usually simpler to use the command line or terminal. One thing IDEs can do for you is indent your code correctly. Your indentation is very poor, and you can hide serious errors from yourself with bad indentation. Please correct the indentation for your own sake.

And . . . welcome to the Ranch
 
Corey Johnson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Campbell I manage to fix my program and I know some sites to use when it comes to pasting in. I had to use NetBeans sadly to do this type of program.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I did to get your code running in NetBeans:

I created a project 'CoreyJohnson'. NetBeans then creates  a public class 'CoreyJohnson' with an empty 'main' method in it.
Then I copied and pasted your code, both the 'ItemSales' and the 'ItemSalesDemo', below the 'CoreyJohnson' class (I had to strip off the 'public', since class 'CoreyJohnson' was already public)
I ran the code, choosing 'ItemSalesDemo' as the class which 'main' method should be executed.

Since you had much trouble getting your code to run, can you tell how you used NetBeans so that it generated the error you mentioned?

But apart from  that: some of your formulas are incorrect. Have you fixed these too?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!