• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Program to Calculate Product and Discount Help Please  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a discount every month in a supermarket. Every "P&G" product is bought there will be 25% discount on the total expenses. If the buyer bought "Wings" product, 10% discount will be given on the total expenses. If he pays with credit card extra 5%charge will be given.
(P&G = $5000, Wings = $4000, Other=$3000)

Example: Product Code: 1.P&G , 2.Wings , 3.Other
Input Product : 2
Input amount : 5

Total expenses : 20000
Discount : 2000
Due: 18000

Do you pay with credit card (Y/N)? Y
Expenses: 900
Due:18900

I hope you understand the question please help thanks
 
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We don't give complete solutions but are happy to help with problems. Please show us what you have so far.
 
Riki Maru
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

We don't give complete solutions but are happy to help with problems. Please show us what you have so far.

to be honest i dont really have any solution for this, in class we never really have started any programming in java but they thought us about making a flowchart.
so yes im new to java. I would be glad if you can help me program this in java and then i will learn from that. Thank you .
 
Campbell Ritchie
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write down what you have on the flowchart. This is a very useful start.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Try this. Change the variable names. try to Change it to use an array option aswell. This is very basic way to do it, so please change it to suit you.
 
Campbell Ritchie
Marshal
Posts: 56605
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please look at this:-
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
which is written on the title page of this forum. It does not help the poster at all if you provide a complete solution. If they hand in that solution, they will get a mark of 0 because it isn't their own work. And youwill only learn something by doing it yourself.
Please don't be annoyed but I have pulled rank and removed the solution (the original is cached in our mysterious Ranch memory).
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a beginner i would suggest first go with flowchart or pseudo code and most important Input,output and processing parameter(IPO). That will help you to understand programming effectively and efficiently.
For your problem mentioned above follow these step
1. get required input values like item(three in your case), no. of item, price
2. use scanner class to get selection for item type
3. use switch for selection
4. take no. of item, calculate payable amount(no. of item * price) and calculate discount (item type*discount/100) on purchase and total payable amount after discount (total expense - discount)
5. use if else or switch for payment type cash/ credit card
6. calculate and apply the final payable amount.
7. display with System.out.prinln statement


hope it would help you
 
Riki Maru
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Please look at this:-
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
which is written on the title page of this forum. It does not help the poster at all if you provide a complete solution. If they hand in that solution, they will get a mark of 0 because it isn't their own work. And youwill only learn something by doing it yourself.
Please don't be annoyed but I have pulled rank and removed the solution (the original is cached in our mysterious Ranch memory).


You might be right but this is not what i expected , im just asking for the code and then from there i will learn(no time wasted for reply and ongoing reply). really dissapointed but thanks for trying to help.
 
Sheriff
Posts: 4932
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he is right. But lets get back to your problem.
Earlier you wrote:
Riki Maru wrote:I hope you understand the question please help thanks
Yes, partially we do understand. But more importantly, do you understand?
Here is the most important part to master, to understand what you have been asked to do. Until that, you should not be looking to any code examples. Because code examples is more about "how" to do, rather than "what" to do. If you don't know what to do, the how part is completely irrelevant.

So, grab the pencil and piece of paper and start writing down the facts you have, and what needs to be done based on these facts. Once you come up, please list them here, we'll see if we agree. Note, do not include any technical aspects, only plain verbal English. Maybe formulas could be considered as a technical part in order to achieve correct calculations with percentages.
 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the earlier illegal post.

I take it you've been learning code for a couple of months now so where to start?

First of all you will always want "public static void main(string [] args){

This will allow you to run the program.

You'll want to create a scanner object so you can get the inputs for your program.

Scanner scn = new scanner(system.in);
The rest will be print ln outputs with variables that you can relate to.

Your main objective here is to create a menu to pick an option, for this I would use a switch statement. Look it up.

For the Creditcard question you should use an if else statement.
Hope this helps
 
Campbell Ritchie
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies accepted

I would do it the other way round; I would start with the classes required to model all the entities in the system and work back towards the whole app. You may wish to create a class with a main method which tests each class as you go, so you can verify they are working properly.
 
Campbell Ritchie
Marshal
Posts: 56605
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said before, try starting with a square class. I showed some tests earlier.
 
Riki Maru
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for trying to help really, i do understand that i should post what i tried(my solution and code) but i forgot to mention that the works was supposed to be submitted today and i had no idea where to start. furthermore i dont have enough time to keep logging in the internet to post reply and ongoing reply just to solve one question, so my point was to get the code/solution asap then from there i will test and see if it works then learn by it. But luckily i have relatives that can help me with the other question(posted on other thread) and because of that i can do the first problem(this) with the similar method as the other question's solution.
i really like the way this forum replied fast and have friendly members , but again some people are more comfortable with practical posted solutions/code that works.
 
Ranch Hand
Posts: 57
3
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riki Maru wrote:i really like the way this forum replied fast and have friendly members , but again some people are more comfortable with practical posted solutions/code that works.


Aside from Campell's original postings, which I completely agree with, I think you need to ask yourself a question - am I actually learning anything by using a solution somebody else posted? Frankly, you're cheating yourself. If you really want to learn about how to program, you'll take your time and understand the fundamentals instead of just asking for code. By learning about what is involved with the programming process, you will find that many times you won't need a complete solution - or any help at all.

To be fair, I don't deny the usefulness of some premade code - but mostly, I go for that when I forget how to instantiate a certain class, or I know the what but not the how. If you don't understand the what, then the how won't do you much good.
 
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riki Maru wrote:but again some people are more comfortable with practical posted solutions/code that works.

I understand your situation.
But believe me, by this way you will not get anything except some assignments to submit.
If you want to continue as a programmer after studies, STAY AWAY from ready solutions/code that works.
Try to solve on your on, post here whatever difficulties you face and people here will be happy to help you get to the solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!