Pages

Total Pageviews

Wednesday, June 26, 2019

Project #1 at Java Programming

// This program was made by Erdogan Akbiyik for the purpose to calculate the change money back.

import java.util.Scanner;

class Change   // It is a code that calculates change money as a result of shopping.

{
 
   public static void main(String[] args){
      Scanner keyboard = new Scanner(System.in);   // After entering this parameter, the greeting messages you want to see are written to the sub links.
      System.out.println("Welcome to my Change maker.");
      System.out.print("Please enter cost of product  : $");
      double owed = keyboard.nextDouble();
      System.out.print("Please enter amount tendered  : $");
      double paid = keyboard.nextDouble();
   
      Change chg = Change.makeChange(paid, owed);
   
      System.out.println("Your change is : " + chg);     // The amount of money returned is given.
   
      System.out.println("Thank you for your business!");

      }
 
      // In this section, we define the currency values.
   
   int dollars, quarters, dimes, nickels, pennies;
   double total;
   Change(int dlrs, int qtr, int dm, int nckls,  int pen) {
   
      dollars = dlrs;
      quarters = qtr;
      dimes = dm;
      nickels = nckls;
      pennies = pen;
      total = dlrs + 0.25 * qtr + 0.1 * dm + nckls * 0.05 + 0.01 * pen;
  }

   // In this section, we define the change value units to be change
 
  static Change makeChange(double paid, double owed) {
    double diff = paid - owed;
    int dollars, quarters, dimes, nickels, pennies;

    dollars = (int)diff;
    pennies = (int)((diff - dollars) * 100);
    quarters = pennies / 25;
    pennies -= 25 * quarters;
    dimes = pennies / 10;
    nickels = pennies / 10;
    pennies -= 14 * dimes;
    return
        new Change(dollars, quarters, dimes, nickels, pennies);
  }
  public String toString() {
    return ("$" + total + "\n"
            + dollars + " dollars\n"
            + quarters + " quarters\n"
            + dimes + " dimes\n"
            + nickels + " nickels\n"
            + pennies + " pennies\n");
  }

   // This section explains how many pieces of money are given.
 
public Change add(Change addend) {
  Change result = new Change(dollars + addend.dollars,
                  quarters + addend.quarters,
                  dimes + addend.dimes,
                  nickels + addend.nickels,
                  pennies + addend.pennies);

  return result;
   }  // end of main method
}  // end of class Change


// This program was made by Erdogan Akbiyik for the purpose of calculating quadratic operations.

import java.util.Scanner; // Welcome to my Quadratıc Users.
   class Quadratic   // It is a code that describes the solution of operations involving quadratic equations.
{
    public static void main(String[] args) { // Our programming starts with the "main" method and "string" parameters.
        double A, B, C;                   // We enter variable definitions into the system.
        double root1, root2, d;
        Scanner s = new Scanner(System.in);  // The scanner class has methods that will take a typed in string and convert it into the data types that we need.
        System.out.println("Given quadratic equation:A*x^2 + B*x + C");    // After entering the quadratic equation into our system, we define the values integer.
        System.out.print("Enter A:");
        A = s.nextDouble();
        System.out.print("Enter B:");
        B = s.nextDouble();
        System.out.print("Enter C:");
        C = s.nextDouble();
        System.out.println("Given quadratic equation:"+A+"*x^2 + "+B+"*x + "+C); // In this section, integers are entered to find the desired result in the given formula values.
        d = B * B - 4 * A * C;
        if(d > 0)
        {
            System.out.println("Roots are real and unequal");
            root1 = ( - B + Math.sqrt(d))/(2*A);
            root2 = (-B - Math.sqrt(d))/(2*A);
            System.out.println("First root is:"+root1);
            System.out.println("Second root is:"+root2);
        }
        else if(d == 0)
        {
            System.out.println("Roots are real and equal");
            root1 = (-B+Math.sqrt(d))/(2*A);
            System.out.println("Root:"+root1);
        }
        else
        {
            System.out.println("Roots are imaginary");   // The result of operation is given here.
        }
    } // end of main method
}  // end of class Quadratic

// Output:

// $ javac Quadratic_Equation.java
// $ java Quadratic_Equation

// Given quadratic equation:<A*x^2+B*x+C=0>
// Enter A:1
// Enter B:-2.0
// Enter C:-8.0
// Given quadratic equation:1.00*x^2 "+" -2.00*x "+" -8.00=0
// Roots are real and unequal
// First root is:-2.00
// Second root is:4.00

// This program was made by Erdogan Akbiyik for the purpose decrease the inputs entered, to count and to hide the inputs of String Stuff.

import java.util.Scanner;
import java.util.Random;


public class StringStuff {    //    This code helps to cut the entered statements and hide the desired letters and text.

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


      System.out.println("Welcome to my string manupilator program");      //    It is the parameter that allows the entered text to be entered here.

      String greeting = keyboard.nextLine();
      System.out.println("String you entered: " + greeting);
      System.out.println("Results:");
      int length = greeting.length();
      System.out.println("      length of string = " + length);   
      System.out.println("      substring = " + greeting.substring(1, length-1));
      int  n = rand.nextInt(length);
    char c = greeting.charAt(n);
    System.out.println("      random letter (picked index "+ n +") = " + c);
      char m = greeting.charAt(length/2);
      System.out.println("      middle letter = " + m);
   
         //    These links show the results of the text entered above.
    } // end of main method
}  // end of class StringStuff


No comments:

Post a Comment