Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package While_Loop_More_Exercises;
- import java.util.Scanner;
- public class Report_System {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int expSum = Integer.parseInt(scan.nextLine());
- String input = scan.nextLine();
- int countOfTransactions = 0;
- double counOfCache = 0;
- double countOfCards = 0;
- double sumOfCards = 0.0;
- double sumOfCache = 0.0;
- while (!"End".equals(input)) {
- int price = Integer.parseInt(input);
- countOfTransactions++;
- if (countOfTransactions % 2 != 0 && price <= 100) {
- counOfCache++;
- sumOfCache += price;
- System.out.println("Product sold!");
- } else if (countOfTransactions % 2 == 0 && price >= 10) {
- countOfCards++;
- sumOfCards += price;
- System.out.println("Product sold!");
- } else {
- System.out.println("Error in transaction!");
- }if (sumOfCache + sumOfCards >= expSum){
- break;
- }else if("End".equals(input)){
- break;
- }
- input = scan.nextLine();
- }
- if (sumOfCache + sumOfCards >= expSum) {
- System.out.printf("Average CS: %.2f%n", sumOfCache / counOfCache);
- System.out.printf("Average CC: %.2f", sumOfCards / countOfCards);
- } else {
- System.out.println("Failed to collect required money for charity.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement