Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Basics


Here is the problem description for the attached Java program: Farmers Market: Write a Java program to perform check-out functionality for a simple Farmers Market store with exactly 5 products: Product - Price per pound Bananas - $ 0.44 Apples - $ 0.99 Cucumbers - $ 1.19 Carrots - $ 0.89 Oranges - $ 0.79 After getting the weight for each product purchase and compute & output the total purchase amount in the end. Do not use loops or arrays in this assignment. You can assume that all the user inputs are valid & the user will enter 0 for products (s)he does not purchase – no need to do any input validation explicitly. Use meaningful variable names & achieve "self-documenting" style of coding. Let us expand program to apply discounts. Share your program in the forum and explain how you did it so that others can benefit from it. Farmers market introduces two types of discounts to attract more customers and make each customer to purchase more. Discount card program to attract customers. All customers who have signed up for it are considered as "special customers" and they get automatic minimum 10% discount off based on the total purchase amount. However, this cannot be combined with other discounts. All customers are eligible for the following discount program. If the total purchase is above $50, 5% discount will apply. If the total purchase exceeds $75, 10% discount will apply. If the total purchase exceeds $100, 15% discount will apply. After computing the total purchase amount, program should determine the discount & output the following items if a discount is applied: discount % and discount amount discounted total Attachments


Answer for KJava Basics


import java.util.Scanner;
import java.text.DecimalFormat;
public class FarmersMarket
public static void main(String[] args)
Scanner keyboard = new Scanner(;

System.out.println("Enter the weight for Bananas: ");
double bananasWeight = keyboard.nextDouble();
double bananasPrice = 0.44 * bananasWeight;
System.out.println("Enter the weight for Apples: ");
double applesWeight = keyboard.nextDouble();
double applesPrice = 0.99 * applesWeight;

System.out.println("Enter the weight for Cucumbers: ");
double cucumbersWeight = keyboard.nextDouble();
double cucumbersPrice = 1.19 * cucumbersWeight;

System.out.println("Enter the weight for Carrots: ");
double carrotsWeight = keyboard.nextDouble();
double carrotsPrice = 0.89 * carrotsWeight;

System.out.println("Enter the weight for Oranges: ");
double orangesWeight = keyboard.nextDouble();
double orangesPrice = 0.79 * orangesWeight;

double totalAmount = bananasPrice + applesPrice + cucumbersPrice
+ carrotsPrice + orangesPrice;

String response; // This is where I initialize the variables
double discount=0;
double percentage=0;
double finalprice=0;
DecimalFormat df = new DecimalFormat("#,###,##0.00"); // This is for formatting the decimal later

System.out.println("Your total purchase amount is $ " + (df.format(totalAmount)));

// These next lines are where the discount is applied. This program works by

// starting at the highest
//discount which is in this...
Attachments Screenshots
Purchase Answer