Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.21 KB | None | 0 0
  1. /*
  2. * File name: GroceryShopping
  3. *
  4. * Programmer: Caleb howard
  5. * ULID: cshowa1
  6. *
  7. * Date: Sep 19, 2019
  8. *
  9. * Class: IT 168
  10. * Lecture Section: 001
  11. * Lecture Instructor: Qi Zhang
  12. * Lab Section: 002
  13. * Lab Instructor: Oluwatoba Paul Adegbite
  14.  */
  15. package edu.ilstu;
  16.  
  17. /**
  18.  *
  19.  * @author Caleb Shawn Howard
  20.  *
  21.  */
  22. public class GroceryShopping {
  23.  
  24.    
  25.    
  26.  
  27.     /**
  28.      * @param args
  29.      *   */
  30.    
  31.     //Instance Variables
  32.          
  33.         private String vegtableName;
  34.         private String fruitName;
  35.         private double vegetablePrice;
  36.         private double fruitPrice;
  37.         private double vegtableordered;
  38.         private double fruitOrdered;
  39.        
  40.     //Constants
  41.        
  42.         private static final double SERVICE_RATE = 0.035;
  43.         private static final int DELIVERLY_FEE = 5;
  44.        
  45.     //Methods  
  46.     /**
  47.      *  The constructor should accept the selected vegetable and fruit names.
  48.      *  Along with the corresponding price per pound as arguments.
  49.      *  The constructor should also assign 0 to the fields of vegetable ordered and fruit ordered.
  50.      * */
  51.    
  52.         public  GroceryShopping( String vegtableName, String fruitName,
  53.                 double vegtableorded ,  double fruitordered
  54.                 ,double fruitPrice, double vegtablePrice ){
  55.            
  56.             this.setVegtableordered(0);
  57.             this.setFruitOrdered(0);
  58.             this.setfruitPrice(0);
  59.             this.setvegetablePrice(0);
  60.             this.vegtableName(vegtableName);
  61.             this.setfruitName(fruitName);
  62.            
  63.         }
  64.        
  65.         //Subtotal Method and AdditionalFee Method
  66.         /**
  67.          * A method that calculates the subtotal based on
  68.          * the selected vegetable and fruit, their price per pound
  69.          * and how many pounds ordered
  70.          * @return subtotal
  71.          */
  72.          
  73.  
  74.         public double calculateSubtotal()
  75.         {
  76.             double subtotal = this.fruitPrice * this.fruitOrdered
  77.                     + this.vegetablePrice * this.vegtableordered;
  78.            
  79.             return subtotal;
  80.             }
  81.        
  82.         /**
  83.          * A method that will calculate the total cost of delivery and
  84.          * service fee of the total vegetable and fruit ordered
  85.          * @return additionalFee
  86.          */
  87.     public double calculateAdditionalFee()
  88.     {
  89.         double additionalFee = this.calculateSubtotal() * SERVICE_RATE + DELIVERLY_FEE;
  90.        
  91.         return additionalFee;
  92.     }
  93.    
  94.     /**
  95.      * Displays the title of “Grocery Shopping Order Summary”,
  96.      * names of the selected vegetable and fruit and the corresponding pounds ordered,
  97.      * as well as the subtotal, additional fee
  98.      * @return displayOrderSummary
  99.      */
  100.     public  String displayOrderSummary()
  101.     {
  102.             System.out.println("Grocery Shopping Order Summary");
  103.             System.out.println("Name \t" + "\t pound ordered:");
  104.             System.out.println(this.vegtableName + "\t" + "\t" + this.vegtableordered);
  105.             System.out.println(this.fruitName + "\t" + "\t"
  106.                     + this.fruitOrdered + "\n" );
  107.             System.out.println("Sub-total: \t" + "\t"
  108.                     + this.calculateSubtotal());
  109.             System.out.println("Additioal Fee: \t"
  110.                     + "\t" + this.calculateAdditionalFee());
  111.             System.out.println( this.calculateSubtotal()
  112.                     + this.calculateAdditionalFee());
  113.             System.out.println("-----------------------------------------");
  114.     return displayOrderSummary();
  115.            
  116.     }
  117.        
  118.     //Getters and Setters
  119.         /**
  120.          * Created Getters for all instance variables
  121.          * Created Setters for pounds of the vegetable and fruit ordered*/
  122.    
  123.         /**
  124.          * Returns the vegtableName
  125.          * @return the vegtableName*/
  126.     public String getVegtableName() {
  127.         return vegtableName;
  128.     }
  129.    
  130.         /**
  131.          * Returns the fruitName
  132.          * @return the fruitName*/
  133.  
  134.     public String getFruitName() {
  135.         return fruitName;
  136.     }
  137.  
  138.         /**
  139.          * Returns the vegtablePrice
  140.          * @return the vegetable price*/
  141.     public double getVegetablePrice() {
  142.         return vegetablePrice;
  143.     }
  144.  
  145.         /**
  146.          * Returns the fruitPrice
  147.          * @return the fruitPrice*/
  148.     public double getFruitPrice() {
  149.         return fruitPrice;
  150.     }
  151.  
  152.         /**
  153.          * @return the vegtableordered
  154.          * Returns the vegtables ordered*/
  155.  
  156.     public double getVegtableordered() {
  157.         return vegtableordered;
  158.     }
  159.     /**
  160.      * setter for vegtableordered
  161.      * @param vegtables ordered*/
  162.  
  163.     public void setVegtableordered(double vegtableordered) {
  164.         this.vegtableordered = vegtableordered;
  165.     }
  166.  
  167.     /**
  168.      * Returns the fruitOrded
  169.      * @return the fruit ordered */
  170.     public double getFruitOrdered() {
  171.         return fruitOrdered;
  172.     }
  173.  
  174.     /**
  175.      * Setter for fruitName
  176.      * @param fruit Name*/
  177.     public void setfruitName(String fruitName) {
  178.         this.fruitName = fruitName;
  179.     }
  180.  
  181.  
  182. /**
  183.  * Setter for vegtableName
  184.  * @param vegtableName*/
  185. public void setFruitOrdered(String vegtableName) {
  186.     this.vegtableName = vegtableName;
  187. }
  188.  
  189.     /**
  190.      * Returns the SERVICE_RATE
  191.      * @return the Service_Rate*/
  192.     public static double getServiceRate() {
  193.         return SERVICE_RATE;
  194.     }
  195.  
  196.     /**
  197.      * Returns the DeliveryFee
  198.      * @return the Delivered Fee */
  199.     public static int getDeliverlyFee() {
  200.         return DELIVERLY_FEE;
  201.         }
  202.     /**
  203.      * Setter for fruitOrdered
  204.      * @param fruit ordered*/
  205.     public void setFruitOrdered(double fruitOrdered) {
  206.         this.fruitOrdered = fruitOrdered;
  207.     }
  208.    
  209.     /**
  210.      * Setter for vegetablePrice
  211.      * @param vegetablePrice*/
  212.     public void setvegetablePrice(double vegtablePrice) {
  213.         this.vegetablePrice = vegtablePrice;
  214.     }
  215.  
  216.     /**
  217.      * Setter for fruitPrice
  218.      * @param fruit price*/
  219.     public void setfruitPrice(double fruitPrice) {
  220.         this.fruitPrice = fruitPrice;
  221.     }
  222.  
  223.    
  224.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement