-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetailPriceCalculator.java
More file actions
97 lines (75 loc) · 2.94 KB
/
RetailPriceCalculator.java
File metadata and controls
97 lines (75 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package ch8;
//****************************************************************
//Ch 8 Program 1 Retail Price Calculator
//Program Name: RetailPriceCalculator.java
//
//Author: PBaker and Josh Decker
//Date Written: 3/18/2022
//Class: CSC110AB ONLINE
//
//Brief Description: Using a user-defined method, calculate the retail
//price of an item given the wholesale cost of the item and its markup percentage.
//Introduces writing and using methods.
//Also includes basic data validation (wholesale cost must be positive).
//*****************************************************************
import java.util.Scanner;
public class RetailPriceCalculator {
public static double calculateRetailPrice(double wholesalePrice, double markupPercent) {
double finalPrice = wholesalePrice + (wholesalePrice * (markupPercent * .01));
return finalPrice;
}
public static void main(String[] args) {
double wholesale;
double markup;
double retailPrice;
char continueProgram = 'y';
Scanner scnr = new Scanner(System.in);
System.out.println("Welcome to the Retail Price Calculator");
System.out.println("--------------------------------------");
do {
// prompt the user for the wholesale cost. Accept only positive values.
System.out.print("Enter the item's wholesale price: ");
wholesale = scnr.nextDouble();
do {
if (wholesale < 0) {
System.out.print("Please re-enter a positve wholesale cost: ");
wholesale = scnr.nextDouble();
}
} while (wholesale < 0);
// prompt the user for the markup percentage
System.out.print("Enter the item's markup percent: ");
markup = scnr.nextDouble();
// call the calculateRetailPrice method and display the retail price
retailPrice = calculateRetailPrice(wholesale, markup);
System.out.printf("The retail price is: " + "$%.2f", retailPrice);
System.out.println("\n");
// ask the user if they would like to continue or not
System.out.print("Do you want to run another calculation? (Y or N): ");
continueProgram = scnr.next().charAt(0);
} while (continueProgram != 'n');
System.out.println("\nGoodbye");
scnr.close();
}
}
/*
Welcome to the Retail Price Calculator
--------------------------------------
Enter the item's wholesale price: 5
Enter the item's markup percent: 100
The retail price is: $10.00
Do you want to run another calculation? (Y or N): y
Enter the item's wholesale price: 20
Enter the item's markup percent: 10
The retail price is: $22.00
Do you want to run another calculation? (Y or N): y
Enter the item's wholesale price: -50
Please re-enter a positve wholesale cost: 50
Enter the item's markup percent: 5
The retail price is: $52.50
Do you want to run another calculation? (Y or N): y
Enter the item's wholesale price: 400
Enter the item's markup percent: 25
The retail price is: $500.00
Do you want to run another calculation? (Y or N): n
Goodbye
*/