Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class JavaExercises {
- public static void main(String[] args) {
- ///////////////////// Section 1 - Building Blocks /////////////////////
- //----------------Ex1------------------
- /*
- Scanner sc = new Scanner(System.in);
- int radius = 0;
- System.out.println("Please enter a circle radius: ");
- radius = sc.nextInt();
- if (radius < 0) {
- radius = 0;
- System.out.println("Radius cannot be negative! Bad Input!");
- } else {
- System.out.printf("A circle with radius of: %dm has a perimeter of: %fm and an area of: %fm^2"
- , radius, Math.PI*radius*radius, 2*radius*Math.PI);
- }
- */
- //----------------Ex2------------------
- /*
- Scanner sc = new Scanner(System.in);
- final int TOAST = 12, CHEAP_EXTRAS = 2, EXP_EXTRAS = 3;
- int toastTotalPrice = TOAST;
- char c = ' ';
- while(true) {
- System.out.println("Please enter the desired extras on the toast. M - Mushrooms, O - Olives, C - Corn, " +
- "B - Bulgarian cheese, E - Extra cheese, X - Go to checkout");
- c = sc.next().charAt(0);
- if(c == 'X' || c == 'x') {
- break;
- }
- switch (c) {
- case 'M' :
- case 'm' :
- case 'O' :
- case 'o' :
- case 'C' :
- case 'c' :
- toastTotalPrice += CHEAP_EXTRAS;
- break;
- case 'B' :
- case 'b' :
- case 'E' :
- case 'e' :
- toastTotalPrice += EXP_EXTRAS;
- break;
- default:
- System.out.println("Invalid Input! Try again");
- }
- }
- System.out.printf("Total toast price is: %d", toastTotalPrice);
- */
- //----------------Ex2------------------
- /*
- Scanner sc = new Scanner(System.in);
- final int PRICE_FOR_ONE_KM_TRANS = 5;
- final int FLOOR_PRICE_FOR_EACH_KG = 1;
- int initPrice = 0;
- int weight = 0;
- int floor = 0;
- int dist = 0;
- System.out.println("Please enter the item's price, its weight, what floor you leave in and the distance from the store: ");
- initPrice = sc.nextInt();
- weight = sc.nextInt();
- floor = sc.nextInt();
- dist = sc.nextInt();
- sc.nextLine();
- sc.close();
- System.out.printf("Total transport price, the item's price included, is: %f",
- initPrice + weight*floor*FLOOR_PRICE_FOR_EACH_KG + PRICE_FOR_ONE_KM_TRANS*dist + initPrice*0.1);
- */
- ///////////////////// Section 2 - Language //////////////////
- //----------------Ex1------------------
- /*
- Scanner sc = new Scanner(System.in);
- int age;
- System.out.println("Please enter your age: ");
- age = sc.nextInt();
- if(age < 18) {
- System.out.println("You are not adult!");
- } else {
- System.out.println("You are an adult!");
- }
- sc.close();
- */
- //----------------Ex2------------------
- /*
- Scanner sc = new Scanner(System.in);
- int age;
- System.out.println("Please enter your age: ");
- age = sc.nextInt();
- if(age < 18) {
- System.out.println("You are not adult!");
- } else if (age < 66){
- System.out.println("You are an adult!");
- } else {
- System.out.println("You are on pension!");
- }
- sc.close();
- */
- //----------------Ex3------------------
- /*
- Scanner sc = new Scanner(System.in);
- int number;
- System.out.println("Please enter a 2 digit number: ");
- number = sc.nextInt();
- sc.close();
- if(number < 10 || number > 99) {
- System.out.println("Bad Input!");
- } else {
- if(number/10 == number%10) {
- System.out.println("Digits are identical!");
- } else {
- System.out.println("Digits are not the same!");
- }
- }
- */
- //----------------Ex4------------------
- /*
- Scanner sc = new Scanner(System.in);
- int number;
- System.out.println("Please enter a 3 digit number: ");
- number = sc.nextInt();
- sc.close();
- if(number < 100 || number > 999) {
- System.out.println("Bad Input!");
- } else {
- if((number/10 == number%100) && (number/100 == number%10)) {
- System.out.println("Digits are identical!");
- } else {
- System.out.println("Digits are not the same!");
- }
- }
- */
- //----------------Ex5------------------
- /*
- Scanner sc = new Scanner(System.in);
- int number;
- System.out.println("Please enter a 2 digit number: ");
- number = sc.nextInt();
- sc.close();
- if(number < 10 || number > 99) {
- System.out.println("Bad Input!");
- } else {
- if(number < 90 && number / 10 == number % 10 - 1) {
- System.out.println("Digits are consecutive!");
- } else {
- System.out.println("Digits are not consecutive!");
- }
- }
- */
- //----------------Ex6------------------
- /*
- Scanner sc = new Scanner(System.in);
- int number;
- System.out.println("Please enter a 3 digit number: ");
- number = sc.nextInt();
- sc.close();
- if(number < 100 || number > 999) {
- System.out.println("Bad Input!");
- } else {
- if(number < 900 && number / 100 == (number % 100 / 10) - 1 && (number % 100 / 10) == number % 10 - 1) {
- System.out.println("Digits are consecutive!");
- } else {
- System.out.println("Digits are not consecutive!");
- }
- }
- */
- //----------------Ex7------------------
- //
- Scanner sc = new Scanner(System.in);
- int maxFuel, currentFuel;
- System.out.println("Please enter size of fuel tank and current fuel in the car: ");
- maxFuel = sc.nextInt();
- currentFuel = sc.nextInt();
- sc.close();
- if(currentFuel < maxFuel * 0.15) {
- System.out.println("Put some gaz on your vehicle!");
- } else {
- System.out.println("Your'e doing just fine!");
- }
- //
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement