Solution for Programming mock exam 2018, Task 3
This video is for FH SWF BBA Students. This is the source code: package myNewProject; import java.util.Scanner; public class myNewClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int lengthOfContract = 0; int isStudent = 99; double price = 19.99; System.out.println("Hi! Welcome to our Fitness Center! Would you like to make contract for 12 or 24 months?"); while(lengthOfContract != 12 && lengthOfContract != 24) { lengthOfContract = sc.nextInt(); if(lengthOfContract != 12 && lengthOfContract != 24) { System.out.println("Please enter '12' or '24'"); } } System.out.println("Good, you want contract for " + lengthOfContract + " months. Are you a student?"); System.out.println("0: No"); System.out.println("1: Yes"); while(isStudent != 0 && isStudent != 1) { isStudent = sc.nextInt(); if(isStudent != 0 && isStudent != 1) { System.out.println("Please enter '0' for 'NO' or '1' for 'YES'"); } } if(isStudent == 1) { price = 14.99; } if(lengthOfContract == 24) { price *= 0.7; } System.out.println("Your monthly price will be: $" + Math.round(price * 100.0) / 100.0); } }
This video is for FH SWF BBA Students. This is the source code: package myNewProject; import java.util.Scanner; public class myNewClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int lengthOfContract = 0; int isStudent = 99; double price = 19.99; System.out.println("Hi! Welcome to our Fitness Center! Would you like to make contract for 12 or 24 months?"); while(lengthOfContract != 12 && lengthOfContract != 24) { lengthOfContract = sc.nextInt(); if(lengthOfContract != 12 && lengthOfContract != 24) { System.out.println("Please enter '12' or '24'"); } } System.out.println("Good, you want contract for " + lengthOfContract + " months. Are you a student?"); System.out.println("0: No"); System.out.println("1: Yes"); while(isStudent != 0 && isStudent != 1) { isStudent = sc.nextInt(); if(isStudent != 0 && isStudent != 1) { System.out.println("Please enter '0' for 'NO' or '1' for 'YES'"); } } if(isStudent == 1) { price = 14.99; } if(lengthOfContract == 24) { price *= 0.7; } System.out.println("Your monthly price will be: $" + Math.round(price * 100.0) / 100.0); } }