There is a JAR full of Candies for sale at a mall
counter. JAR has the capacity N, that is JAR can
contain maximum N Candies when JAR is full.
At any point of time, JAR can have M number of
Candies where M <= N. Candies are served to
the customers. JAR is never remaining empty as
when last k candies are left, JAR is refilled with
new Candies in such a way that JAR gets full.
Write the code to implement above scenario.
Display JAR at Counter with available number of
candies. Input should be number of candies one
customer orders at point of time. Update the
JAR after every purchase and display JAR at
Counter.
Output should give number of Candies sold and
updated number of Candies in JAR.
If input is more than number of Candies in JAR,
return: "INVALID INPUT"
Given,
N= 10 ,where N is NUMBER OF CANDIES
AVAILABLE
k =< 5, where k is number of minimum Candies
Answers
Answered by
1
Answer:
Sorry i am not able to understand what to do in this question
Answered by
2
Answer:
import java.util.Scanner;
class Main{
public static void main(String[] args) {
int n = 10, k = 5;
int num;
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
//k<=5 and not k==0
if(num >= 1 && num <= 5) {
System.out.println("NUMBER OF CANDIES SOLD : " + num);
System.out.print("NUMBER OF CANDIES LEFT : " + (n - num));
} else {
// if k==0
System.out.println("INVALID INPUT");
System.out.print("NUMBER OF CANDIES LEFT : " + n);
}
}
}
Explanation:
Similar questions