Pages

Total Pageviews

Saturday, June 29, 2019

Project #2 at Java Programming

// This program was made by Erdogan Akbiyik

/*
Project 2 Digits Program - The purpose of this program is The number which is only divisible by itself and 1 is known as prime number.
*/

import java.util.*;  // Welcome users :)
public class Digits{ //  In the first step we create our java file and class.
// In this program we will use to calculate finding the odd numbers in the given numbers.
// We enter the given values after writing the string method.
   
      public static void main(String[] args) {
      Scanner keyboard=new Scanner(System.in);

// We create the range that are required to find the odd numbers in the entered numbers.

System.out.print("enter the number : ");
      int number=keyboard.nextInt();
      int counter=0;
      int unit_digit, left_part_of_number;

      unit_digit=(number%10);

if ((unit_digit%2)!=0){
   counter++;
   System.out.println("single number found : "+ unit_digit);
}

left_part_of_number=(number/10);

while (left_part_of_number>0){
unit_digit=(left_part_of_number%10);
if ((unit_digit%2)!=0){
 counter++;
System.out.println("single number found : "+ unit_digit);
}
left_part_of_number=(left_part_of_number/10);

}
// In the last step we find the odd numbers in the data we entered.
System.out.println("There are "+counter+" odd digits.");

   }  // End of main method
}  // End of class Digits


// Enjoy the program and good bye :)


// This program was made by Erdogan Akbiyik

// This program was made by Erdogan Akbiyik

/*
Project 2 Discount Program - The purpose of this program is to calculate the discounts in product purchases.
*/
import java.util.*;  //   Welcome users :)
  class Discount   { //  In the first step we create our java file and class.
// In this program we will calculate the discount in purchased coffee bags.
// We enter the given values and size of boxes after writing the string method. 
  public static void main(String [] args) {
         final double COFFEE_BAG_PRICE = 5.50;
         final double LARGE_BOX_PRICE = 1.80;
         final double MEDIUM_BOX_PRICE = 1.00;
         final double SMALL_BOX_PRICE = 0.60;

             double bulkDiscount = 10;
             double coffeeBagsOrdered, coffeeCost, subTotal, discountAmount, totalCost;

             int Large, Medium, Small;
           
// We are scanning the data of the total number of products to be purchased and the amount of the products to be discounted.         

      Scanner input = new Scanner(System.in);
   System.out.println("Welcome to my program users");
   System.out.println("Number of Bags Ordered: ");

    coffeeBagsOrdered = input.nextDouble();
           

    coffeeCost=coffeeBagsOrdered*COFFEE_BAG_PRICE;

    System.out.println(coffeeBagsOrdered + " - $" + coffeeCost);

                if(coffeeBagsOrdered <= 24) { bulkDiscount = 0.00; }

                if(coffeeBagsOrdered >= 25 && coffeeBagsOrdered<49) { bulkDiscount = 0.05; }

                if(coffeeBagsOrdered >= 50 && coffeeBagsOrdered< 99) { bulkDiscount = 0.10; }

                if(coffeeBagsOrdered >= 100 && coffeeBagsOrdered<149) { bulkDiscount = 0.15; }

                if(coffeeBagsOrdered >= 150 && coffeeBagsOrdered<199) { bulkDiscount = 0.20; }

                if(coffeeBagsOrdered >= 200 && coffeeBagsOrdered<299) { bulkDiscount = 0.25; }

                if(coffeeBagsOrdered >= 300) { bulkDiscount = 0.30; }

                 discountAmount=coffeeCost*bulkDiscount;



 // We enter discount rates according to the number of ordered products.
    System.out.println("Discount: " + bulkDiscount*100 + "% - $" + discountAmount);

                subTotal=coffeeCost - discountAmount;

                System.out.println("subTotal" + subTotal);

                Large = (int) coffeeBagsOrdered/20;
                Medium = (int) (coffeeBagsOrdered%20)/10;
                Small = (int) (coffeeBagsOrdered%20)/10;
             

                double largeAmount, mediumAmount, smallAmount;

                largeAmount=Large*LARGE_BOX_PRICE;
                mediumAmount=Medium*MEDIUM_BOX_PRICE;
                smallAmount=Small*SMALL_BOX_PRICE;
             
// In the last step we find total charge of the ordered product after the discount.
     System.out.println("Boxes Used:");

                if(Large > 0) { System.out.println("\t" + Large + " Large - $" + largeAmount); }

                if(Medium > 0) { System.out.println("\t" + Medium + " Medium - $" + mediumAmount); }

                if(Small > 0) { System.out.println("\t" + Small +" Small - $" + smallAmount); }

                totalCost = subTotal + largeAmount + mediumAmount + smallAmount;

                System.out.println("Your total charge is: $" + totalCost);                 
                System.out.println("Thank you for my programming");
     }   // End of main method
}  // End of class Discount

 



// Example of Outputfor Discount.java
// Please enter the number of bags of coffee you wish to purchase:52

// Number of Bags Ordered  :  52 -  $286.00
//                Discount :  10% - $28.60
//       Box Used          :
//                   2 Large  -  $3.00
//                   1 Medium -  $1.00
//                   1 Small  -  $0.60

// Your total charge is    :        $262.60

// This program was made by Erdogan Akbiyik

// This program was made by Erdogan Akbiyik

/*
Project 2 Perfect Program - The purpose of this program isdefined as a number that equals the sum of its divisors.
*/

import java.util.Scanner;  // Welcome users :)
public class Perfect {  // In the first step we create our java file and class.
// In this program we will calculate use the modulus operator to find which numbers are divisors.
// We enter the given values numbers after writing the string method.
public static boolean Isperfect(int number)
    {
        int sum=0;
        for(int i = 1 ; i < number ; i++){
            if(number%i==0){
System.out.println("The number that you entered is a number that divides =" + i);
                sum+=i;
System.out.println("Sum =" + sum);
}

}

// The code index that tests the values entered in the Boolean range is true and false.

        if(sum==number)
            return true;
        else
            return false;

    }

// In last step we are defining the numbers given in this directory with the String range.
 
public static void main(String[] args) {



Scanner input = new Scanner(System.in);
int number;

do{
System.out.print("Enter a number = ");
number = input.nextInt();

if (number<0){
System.out.println("You entered a negative number. Ending the program");
break;
}

System.out.println("The number you entered = " + number);

if (Isperfect(number) == true)
System.out.println("The number you entered and the total. The number you entered was perfect");
else
    System.out.println("The number you entered and the total is not equal. The number you entered is not perfect.");
}while (number>0);

    } // End of main method

}  // End of class Perfect


// Enjoy the program and good bye :)



// This program was made by Erdogan Akbiyik

// This program was made by Erdogan Akbiyik

/*
Project 2 Prime Program - The purpose of this program is The number which is only divisible by itself and 1 is known as prime number.
*/
import java.util.Scanner;  //   Welcome users :)
public class Prime { // In the first step we create our java file and class.
// In this program we will calculate that the values given prime numbers.
// We define the maximum and minimum values of numbers after writing the string method.

    public static void main(String[] args) {
    Scanner keyboard=new Scanner(System.in);


System.out.print("Please enter in the lower bound for my search:");
int a=keyboard.nextInt();

System.out.print("Please enter in the upper bound for my search:");
int b=keyboard.nextInt();

// In last step we define the prime numbers with the Loop range.

int totalprimenumber=0;
 
if (a>0 || b>0){
    int counter;
    for (int i=a; i<=b; i++){
        counter=0;

        for (int j=2; j<=a; j++){
            if (i%j==0)
                counter++;
        }
        if (counter==0){
            System.out.println(i);
            totalprimenumber++;
        }
    }
}
            System.out.println("There were " + totalprimenumber + " primes found between " +a+ " and "+b);


    }  // End of main method
}   // End of class Prime


// Enjoy the program and good bye :)



// Example of Outputfor Prime.java
// Please enter in the lower bound for my search: 12
// Please enter in the upper bound for my search: 29
// Prime found:
// 13
// 17
// 19
// 23
// 29
// There were 5 primes found between 12 and 29.


// This program was made by Erdogan Akbiyik


http://erdoganakbiyik.blogspot.com/
https://www.youtube.com/channel/UCDsUnmBfVdEPkcC8FlzPKcg

No comments:

Post a Comment