Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File name: GroceryShopping
- *
- * Programmer: Caleb howard
- * ULID: cshowa1
- *
- * Date: Sep 19, 2019
- *
- * Class: IT 168
- * Lecture Section: 001
- * Lecture Instructor: Qi Zhang
- * Lab Section: 002
- * Lab Instructor: Oluwatoba Paul Adegbite
- */
- package edu.ilstu;
- /**
- *
- * @author Caleb Shawn Howard
- *
- */
- public class GroceryShopping {
- /**
- * @param args
- * */
- //Instance Variables
- private String vegtableName;
- private String fruitName;
- private double vegetablePrice;
- private double fruitPrice;
- private double vegtableordered;
- private double fruitOrdered;
- //Constants
- private static final double SERVICE_RATE = 0.035;
- private static final int DELIVERLY_FEE = 5;
- //Methods
- /**
- * The constructor should accept the selected vegetable and fruit names.
- * Along with the corresponding price per pound as arguments.
- * The constructor should also assign 0 to the fields of vegetable ordered and fruit ordered.
- * */
- public GroceryShopping( String vegtableName, String fruitName,
- double vegtableorded , double fruitordered
- ,double fruitPrice, double vegtablePrice ){
- this.setVegtableordered(0);
- this.setFruitOrdered(0);
- this.setfruitPrice(0);
- this.setvegetablePrice(0);
- this.vegtableName(vegtableName);
- this.setfruitName(fruitName);
- }
- //Subtotal Method and AdditionalFee Method
- /**
- * A method that calculates the subtotal based on
- * the selected vegetable and fruit, their price per pound
- * and how many pounds ordered
- * @return subtotal
- */
- public double calculateSubtotal()
- {
- double subtotal = this.fruitPrice * this.fruitOrdered
- + this.vegetablePrice * this.vegtableordered;
- return subtotal;
- }
- /**
- * A method that will calculate the total cost of delivery and
- * service fee of the total vegetable and fruit ordered
- * @return additionalFee
- */
- public double calculateAdditionalFee()
- {
- double additionalFee = this.calculateSubtotal() * SERVICE_RATE + DELIVERLY_FEE;
- return additionalFee;
- }
- /**
- * Displays the title of “Grocery Shopping Order Summary”,
- * names of the selected vegetable and fruit and the corresponding pounds ordered,
- * as well as the subtotal, additional fee
- * @return displayOrderSummary
- */
- public String displayOrderSummary()
- {
- System.out.println("Grocery Shopping Order Summary");
- System.out.println("Name \t" + "\t pound ordered:");
- System.out.println(this.vegtableName + "\t" + "\t" + this.vegtableordered);
- System.out.println(this.fruitName + "\t" + "\t"
- + this.fruitOrdered + "\n" );
- System.out.println("Sub-total: \t" + "\t"
- + this.calculateSubtotal());
- System.out.println("Additioal Fee: \t"
- + "\t" + this.calculateAdditionalFee());
- System.out.println( this.calculateSubtotal()
- + this.calculateAdditionalFee());
- System.out.println("-----------------------------------------");
- return displayOrderSummary();
- }
- //Getters and Setters
- /**
- * Created Getters for all instance variables
- * Created Setters for pounds of the vegetable and fruit ordered*/
- /**
- * Returns the vegtableName
- * @return the vegtableName*/
- public String getVegtableName() {
- return vegtableName;
- }
- /**
- * Returns the fruitName
- * @return the fruitName*/
- public String getFruitName() {
- return fruitName;
- }
- /**
- * Returns the vegtablePrice
- * @return the vegetable price*/
- public double getVegetablePrice() {
- return vegetablePrice;
- }
- /**
- * Returns the fruitPrice
- * @return the fruitPrice*/
- public double getFruitPrice() {
- return fruitPrice;
- }
- /**
- * @return the vegtableordered
- * Returns the vegtables ordered*/
- public double getVegtableordered() {
- return vegtableordered;
- }
- /**
- * setter for vegtableordered
- * @param vegtables ordered*/
- public void setVegtableordered(double vegtableordered) {
- this.vegtableordered = vegtableordered;
- }
- /**
- * Returns the fruitOrded
- * @return the fruit ordered */
- public double getFruitOrdered() {
- return fruitOrdered;
- }
- /**
- * Setter for fruitName
- * @param fruit Name*/
- public void setfruitName(String fruitName) {
- this.fruitName = fruitName;
- }
- /**
- * Setter for vegtableName
- * @param vegtableName*/
- public void setFruitOrdered(String vegtableName) {
- this.vegtableName = vegtableName;
- }
- /**
- * Returns the SERVICE_RATE
- * @return the Service_Rate*/
- public static double getServiceRate() {
- return SERVICE_RATE;
- }
- /**
- * Returns the DeliveryFee
- * @return the Delivered Fee */
- public static int getDeliverlyFee() {
- return DELIVERLY_FEE;
- }
- /**
- * Setter for fruitOrdered
- * @param fruit ordered*/
- public void setFruitOrdered(double fruitOrdered) {
- this.fruitOrdered = fruitOrdered;
- }
- /**
- * Setter for vegetablePrice
- * @param vegetablePrice*/
- public void setvegetablePrice(double vegtablePrice) {
- this.vegetablePrice = vegtablePrice;
- }
- /**
- * Setter for fruitPrice
- * @param fruit price*/
- public void setfruitPrice(double fruitPrice) {
- this.fruitPrice = fruitPrice;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement