Can i get some help making this java program? Decision Structures This program w
ID: 3676140 • Letter: C
Question
Can i get some help making this java program?
Decision Structures This program will calculate the cost of having a framed picture for customers. After the customer enters the appropriate prompted values, the program will calculate the cost of the framing based on the specifications outlined below. The program should allow the user to order a second frame if desired I. Define a java instance class as described below. Save the class definition in a file with an appropriate filename. Class Name Frame Instance Variables: length - float (representing inches) Fields) width float (representing inches) type - char (valid values P, W, or M for Plastic, Wood, or Metal) matte-integer (representing the number of matting layers) Static Variable: count-tracks the number of frames created Instance Methods: A constructor that accepts no arguments and sets default values as follows: the length to 8, width to 10, type to W, and matte to 1 A constructor that accepts 4 arguments, and sets the fields appropriately. getArea() A method to calculate and return the area of the frame. getType() A method to return frame type. getMatte) A method to return the number of matting layers. toStringo Displays the object's attributesExplanation / Answer
TestFrame.java
package com.test.chegg;
import java.util.Scanner;
/**
* Class to Calculate the cost of the frame
*
* @author YourName
*
*/
public class TestFrame {
// Constants declaration for fixed rates
static final float PLASTIC = 10;
static final float WOOD = 22;
static final float METAL = 31;
static Scanner sc = null;
public static void main(String[] args) {
sc = new Scanner(System.in);// Instantiating Scanner class
Frame frame = makeFrame();// Creating a frame
Frame.count++;// Increment the counter
double cost = calcCost(frame);// Calculating the frame cost
System.out.println("The Cost of the Picture:$ " + cost
+ frame.toString());// Displaying the result
System.out.println("Do you want another picture");// Asking user for
// another picture
String choice = sc.next();// Reading input from user
double cost2 = 0;
if ("Yes".equalsIgnoreCase(choice) || "Y".equalsIgnoreCase(choice)) {
Frame frame2 = makeFrame();// Creating second frame
cost2 = calcCost(frame2);// Calculating cost of the frame
Frame.count++;// Increment the counter
// Displaying the results
System.out.println("The number of frames created:" + Frame.count);
double totalCost = cost + cost2;
System.out.println("The total cost of the pictures:" + totalCost);
System.out.println("Average pictures cost:" + totalCost
/ Frame.count);
} else {
System.out.println("The number of frames created:" + Frame.count);
double totalCost = cost + cost2;
System.out.println("The total cost of the pictures:" + totalCost);
System.out.println("Average pictures cost:" + totalCost
/ Frame.count);
}
sc.close();// Closing the Scanner
}
/**
* Method to Calculate the Cost of the frame
*
* @param frame
* @return totalCost
*/
private static double calcCost(Frame frame) {
double totalCost = 0;
double mattCost = 0;
double cost = 0;
int matt = frame.getMatte();// getting the matte value
float area = frame.getArea();// get the area of a frame
// Based on frame type we are calculating the cost.if invalid frame type
// we are taking it as plastic
switch (frame.getType()) {
case 'P' | 'p':
if (area > 100) {
cost = PLASTIC + 12.50;
} else {
cost = PLASTIC;
}
break;
case 'W' | 'w':
if (area > 100) {
cost = WOOD + 12.50;
} else {
cost = WOOD;
}
break;
case 'M' | 'm':
if (area > 100) {
cost = METAL + 12.50;
} else {
cost = METAL;
}
break;
default:
if (area > 100) {
cost = PLASTIC + 12.50;
} else {
cost = PLASTIC;
}
break;
}
// calculating matte charges
for (int i = 1; i < matt; i++) {
mattCost += 7.25;
}
totalCost = cost + mattCost;
return totalCost;
}
/**
* Method to create a frame
*
* @return Frame
*/
private static Frame makeFrame() {
System.out.println("Enter the length of the frame:");
float len = sc.nextFloat();// Reading input from user
System.out.println("Enter the width of the frame:");
float wid = sc.nextFloat();// Reading input from user
System.out.println("Enter the type of the frame:");
char typ = sc.next().charAt(0);// Reading input from user
System.out.println("Enter the matte of the frame:");
int mat = sc.nextInt();// Reading input from user
Frame frame = new Frame(len, wid, typ, mat);// Instantiating object of
// frame
return frame;
}
}
Frame.java
package com.test.chegg;
/**
* Frame Class for Calculating the cost of Frame
*
* @author YourName
*
*/
public class Frame {
// Instance Variables
private float length;
private float width;
private char type;
private int matte;
// Static variable
public static int count;
// Default Constructor
public Frame() {
this.length = 8;
this.width = 10;
this.type = 'W';
this.matte = 1;
}
// Constructor with multiple arguments
public Frame(float len, float wid, char typ, int mat) {
this.length = len;
this.width = wid;
this.type = typ;
this.matte = mat;
}
/**
* @return the length
*/
public float getLength() {
return length;
}
/**
* @param length
* the length to set
*/
public void setLength(float length) {
this.length = length;
}
/**
* @return the width
*/
public float getWidth() {
return width;
}
/**
* @param width
* the width to set
*/
public void setWidth(float width) {
this.width = width;
}
/**
* @return the type
*/
public char getType() {
return type;
}
/**
* @param type
* the type to set
*/
public void setType(char type) {
this.type = type;
}
/**
* @return the matte
*/
public int getMatte() {
return matte;
}
/**
* @param matte
* the matte to set
*/
public void setMatte(int matte) {
this.matte = matte;
}
/**
* Method to calculate the are of a frame
*
* @return area
*/
public float getArea() {
float area = getLength() * getWidth();
return area;
}
public String toString() {
return " Lenght= " + length + " Width= " + width + " Type= " + type
+ " Matte= " + matte;
}
}
Output:
Enter the length of the frame:
12
Enter the width of the frame:
8
Enter the type of the frame:
P
Enter the matte of the frame:
1
The Cost of the Picture:$ 10.0 Lenght= 12.0 Width= 8.0 Type= P Matte= 1
Do you want another picture
yes
Enter the length of the frame:
8
Enter the width of the frame:
10
Enter the type of the frame:
W
Enter the matte of the frame:
2
The number of frames created:2
The total cost of the pictures:27.25
Average pictures cost:13.625