Hey guys,
I have seen a lot of similar questions in the archives, but I can't find a scenario like the problem I'm having.
Below is my code. I'm running into erros with "finalPrice" and "grandTotalPrice" may not have been initialized. The lines of code are towards the end of the program.
The variables should be assigned totals via console input from above. I'm not sure what the error is, or why. Can anyone please help me out, and explain?
THANKS!!! in advance.
Code:
import java.util.*;
public class PictureFrames
{
static Scanner console = new Scanner(System.in);
static final double REGULAR_FRAME = .15, FANCY_FRAME = .25;
static final double COLOR = .10, CARDBOARD = .02, GLASS = .07, CROWNS = .35;
public static void main (String[] args)
{
double length, width, area, perimeter;
double priceOfFrame, priceOfColor, priceOfCardboard, priceOfGlass, priceOfCrowns, finalPrice, crownFinalPrice, grandTotalPrice;
int numberOfCrowns;
char typeOfFrame, choiceOfColor, choiceOfCrowns;
System.out.println ("Please enter the length of your picure in inches:");
length = console.nextDouble();
System.out.println ("Please enter the width of your picure in inches: ");
width = console.nextDouble();
System.out.println ("Please enter the type of frame: R or r (Regular), F or f (Fancy). ");
typeOfFrame = console.next().charAt(0);
System.out.println ("Would you like to add color?: Y for (Yes), N for (No): ");
choiceOfColor = console.next().charAt(0);
switch (typeOfFrame)
{
case 'R':
case 'r':
if (choiceOfColor == 'N')
{
area = (length * width);
perimeter = (2 * length) + (2 * width);
priceOfFrame = (perimeter * REGULAR_FRAME);
priceOfCardboard = (area * CARDBOARD);
priceOfGlass = (area * GLASS);
finalPrice = (priceOfFrame + priceOfCardboard + priceOfGlass);
break;
}
else if (choiceOfColor == 'Y')
{
area = (length * width);
perimeter = (2 * length) + (2 * width);
priceOfColor = (area * COLOR);
priceOfFrame = (perimeter * REGULAR_FRAME);
priceOfCardboard = (area * CARDBOARD);
priceOfGlass = (area * GLASS);
finalPrice = (priceOfFrame + priceOfColor + priceOfCardboard + priceOfGlass);
break;
}
case 'F':
case 'f':
if (choiceOfColor == 'N')
{
area = (length * width);
perimeter = (2 * length) + (2 * width);
priceOfFrame = (perimeter * FANCY_FRAME);
priceOfCardboard = (area * CARDBOARD);
priceOfGlass = (area * GLASS);
finalPrice = (priceOfFrame + priceOfCardboard + priceOfGlass);
break;
}
else if (choiceOfColor == 'Y')
{
area = (length * width);
perimeter = (2 * length) + (2 * width);
priceOfColor = (area * COLOR);
priceOfFrame = (perimeter * FANCY_FRAME);
priceOfCardboard = (area * CARDBOARD);
priceOfGlass = (area * GLASS);
finalPrice = (priceOfFrame + priceOfColor + priceOfCardboard + priceOfGlass);
break;
}
}
System.out.println ("Would you like to add crowns? Enter Y (Yes), or N (No): ");
choiceOfCrowns = console.next().charAt(0);
if (choiceOfCrowns == 'Y')
{
System.out.println ("How many crowns would you like? ");
numberOfCrowns = console.nextInt();
crownFinalPrice =(numberOfCrowns * CROWNS);
grandTotalPrice = (crownFinalPrice + finalPrice);
}
else if (choiceOfCrowns == 'N')
System.out.printf ("Your total comes to: $%.2f%n", grandTotalPrice);
}
}