Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a console-based application that computes the price of a desk and whose M

ID: 3668899 • Letter: C

Question

Create a console-based application that computes the price of a desk and whose Main() method calls four other methods:

A method to accept the number of drawers in the desk as input from the keyboard. This method returns the number of drawers to the Main() method.

A method to accept as input and return the type of wood - 'm' for mahogany, 'o' for oak, or 'p' for pine.

A method that accepts the number of drawers and wood type, and calculates the cost of the desk based on the following:

Pine desks are $100.

Oak desks are $140.

All other woods are $180.

A $30 surcharge is added for each drawer.

This method returns the cost to the Main() method.

A method to display all the details and the final price.

Explanation / Answer

import java.util.Scanner;


public class ComputeDiskPrice {
static Scanner sc=new Scanner(System.in);

static int numberOfDrawers()
{

    System.out.println("Enter number of drawers");
return sc.nextInt();    
}

static char TypeOfWood(String Typoo)
{

if(Typoo.equals("mahogany"))
{
return 'm';
}
if(Typoo.equals("oak"))
    {
    System.out.println("Inside oaak");
    return 'o';
    }
if(Typoo.equals("pine"))
{
    return 'p';
}
return 0;
}

static float CostOfDesk(int numberOfDrawers,char type)
{
    float total=0.0f;
    if(type=='p')
    {
        total= numberOfDrawers*100*30;
    }
    else if(type=='o')
    {
        total= numberOfDrawers*140*30;
    }
    else if(type=='m')
    {
        total= numberOfDrawers*180*30;
    }
    System.out.println("Total cost "+total);
    return total;
}




   
    public static void main(String[] args) {

int numofdraw=numberOfDrawers();
System.out.println("Enter type");
        String str=sc.next();
        char c=TypeOfWood(str);
        System.out.println("Total cost is ");
        System.out.println(CostOfDesk(numofdraw, c));
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote