Thursday, September 5, 2013

First Java project, creates a receipt for cashier

package project1;

import java.util.Scanner;

import java.util.Random;
import java.text.NumberFormat;

/**

* Tony Antony
* CSIT 210 - Project 1
* Overview: Gets franchise name and converts it to all uppercase, then displays a total of all  sales with a 9 digit confirmation code 
* Input: franchise name and number of each sizes sold
* Output: franchise name, number each size sold, prices of each size, total of each size, and final total of all sales
* Variables: CHILD_PRICE, MEDIUM_PRICE, LARGE_PRICE, EXTRA_LARGE_PRICE, childSales, mediumSales, largeSales, extraLargeSales, 
*            childTotal, mediumTotal, largeTotal, extraLargeTotal, finalTotal, confirmation_code, franchise
* Plan: 
* 1. Gets the franchise name as a String 
* 2. Gets the number of child, medium large and extra large sizes sold as integers
* 3. Converts the franchise name to all uppercase
* 4. calculates totals for each as doubles
* 5. displays the franchise name and receipt in currency format to screen
* @version 1.0 09.26.2013
*/

public class Project1 {


    public static void main(String[] args) {

        
        // declaring prices of each sizes as constants
        final double CHILD_PRICE, MEDIUM_PRICE, LARGE_PRICE, EXTRA_LARGE_PRICE;
        
        // declaring variables needed
        long confirmation_code;
        int childSales, mediumSales, largeSales, extraLargeSales;
        double childTotal, mediumTotal, largeTotal, extraLargeTotal, finalTotal;
        String franchise;
        
        // assigning values to each sizes
        CHILD_PRICE = 1.23;
        MEDIUM_PRICE = 2.34;
        LARGE_PRICE = 3.45;
        EXTRA_LARGE_PRICE = 4.56;  
       
        // starting new scanner and random objects
        Scanner scan = new Scanner(System.in);
        
        Random rand = new Random();
        
        // displays 9 dight random number between 100000000 and 900000000
        confirmation_code = rand.nextInt(900000000)+100000000;
        
        // currency number format option
        NumberFormat format = NumberFormat.getCurrencyInstance();     

        // getting user inputs for franchise name and how many each sizes sold

        System.out.print("Enter name of franchise: ");
        franchise = scan.nextLine();
        System.out.print("Enter child sizes sold: ");
        childSales = scan.nextInt();
        System.out.print("Enter medium sizes sold: ");
        mediumSales = scan.nextInt();
        System.out.print("Enter large sizes sold: ");
        largeSales = scan.nextInt();
        System.out.print("Enter extra large sizes sold: ");
        extraLargeSales = scan.nextInt();
        
        // adding extra blank line between user input and output
        System.out.println();
        
        // equation to find totals for each size
        childTotal = CHILD_PRICE * childSales;
        mediumTotal = MEDIUM_PRICE * mediumSales;
        largeTotal = LARGE_PRICE * largeSales;
        extraLargeTotal = EXTRA_LARGE_PRICE * extraLargeSales;        
        finalTotal = childTotal + mediumTotal + largeTotal + extraLargeTotal;
        
        // converts the franchise name to all uppercase and displays the bill in currency format
        System.out.println("\t\t\t    " + franchise.toUpperCase());
        System.out.println("\t\t\t//----//----~----\\\\----\\\\");
        System.out.println("\t\t# of Sales\tPrice\t\tTotal");
        System.out.println("Child\t\t" + childSales +"\t\t" + format.format(CHILD_PRICE) + "\t\t" + format.format(childTotal));
        System.out.println("Medium\t\t" + mediumSales +"\t\t" + format.format(MEDIUM_PRICE) + "\t\t" + format.format(mediumTotal));
        System.out.println("Large\t\t" + largeSales +"\t\t" + format.format(LARGE_PRICE) + "\t\t" + format.format(largeTotal));
        System.out.println("Extra Large\t" + extraLargeSales +"\t\t" + format.format(EXTRA_LARGE_PRICE) + "\t\t" + format.format(extraLargeTotal));
        System.out.println();
        System.out.println("\t\tTotal:\t\t\t\t" + format.format(finalTotal));
        System.out.println("\t\tConfirmation code: " + confirmation_code);        
        
    }
}







No comments:

Post a Comment