patingin naman po ng code mga sir/ma'am, di po kasi nagtuturo prof namin ngayong online class, Naghahanap po ako sa internet pero di ko po gets. Pa help naman po matapos tong code salamat po! iintindihin ko nalang po since mas madali ata dito matuto pag may pro coder.
This is really simple but I don't want to spoon feed the solution. I'll give you hints and questions instead.
1. Do you know how to print a string to the terminal?
2. Do you know how to create a variable?
3. Do you know basic arithmetic? What's 1 + 1? What about 500 * 80%?
4. Do you know how to compute the discount using pen and paper only?
5. Do you know how to create a simple Class in Java? A simple static method?
6. Do you understand in your own words what the business problem is? This is English comprehension.
If the answer is no to any of these, go learn those first before tackling this programming problem.
If the answer is yes to all of these, here's what you should do. Divide and conquer the problem into smaller functions, simple classes or static methids. Whichever is easier for you.
Create a function that only does the discount computation.
Create a function that just accepts the input
Create a function that validates input
Create a function that prints the output.
Yes you can write these as one giant function but this is often what leads to confusion among beginners. They write poorly organized code which leads to bugs and harder to understand codes.
Also if you search hard enough, there's already similar programs in this forum doing some form of what the problem is asking. You really just have to massage the program.
Also I doubt that you've searched hard enough online via Google. I bet you I can find similar solutions if I do the search. Knowing how to search is an important skill. You don't need to be a programmer to become good at searching by the way.
Google mo to:
1. How to enter value in Java.
2. Condition and Loop in Java
3. Basic Arithmetic.
tapos iFrankenstein mo nalang HAHAHAHA
same concept pero coded in python,
total = []
#List sa python, Array tawag sa java.
for i in range(3):
#code will loop 3x
a = int(input('Enter price of item {}: '.format(i+1)))
total.append(a)
#total.append(a) would pass the value of var a to var total
print('Total is {}'.format(sum(total)))
if sum(total) < 500:
print('No discount')
d = 0
elif sum(total) < 800:
print('20% discount')
d = 0.20
elif sum(total) < 1000:
print('30% discount')
d = 0.30
else:
print('50% discount')
d = 0.50