Examine the driver program below. class Test2A { public static void main ( Strin
ID: 668031 • Letter: E
Question
Examine the driver program below.
class Test2A
{ public static void main ( String [] args )
{ Desk d = new Desk (60, 45, "UCT");
System.out.println ("Surface area is: "+d.getSurfaceArea ());
System.out.println ("Desk owner is: "+d.getOwner ()); } }
Write the Desk class, containing:
• a constructor that takes width,depth and owner as parameters;
• getSurfaceArea that returns the area of the desk;
• getOwner that returns the owner; and
• appropriate instance variables.
Sample Output:
Surface area is: 2700
Desk owner is: UCT
Explanation / Answer
PROGRAM FOR DESK CLASS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Desk
{
int deskLength;
int deskWidth;
string deskWood;
int deskDrawers;
int mahogcost = 160;
int oakCost = 110;
int surfaceCharge;
int drawerCost;
double taxAmt = 0.09;
int totalCost;
public int DrawerCost
{
get{return drawerCost;}
set{drawerCost = value;}
}
public int DeskLength
{
get { return deskLength; }
set { deskLength = value;CalculateAreacost(); }
}
public int DeskWidth
{
get { return deskWidth; }
set { deskWidth = value;CalculateAreacost(); }
}
public string DeskWood
{
get { return deskWood; }
set { deskWood = value; }
}
public int DeskDrawers
{
get { return deskDrawers; }
set { deskDrawers = value;CalculateDrawer(); }
}
public int SurfaceCharge
{
get { return surfaceCharge; }
set { surfaceCharge = value; }
}
public void CalculateDrawer()
{
drawerCost = 30 * DeskDrawers;
}
public void CalculateAreacost()
{
if (DeskLength * DeskWidth > 720) surfaceCharge = 50;
else surfaceCharge = 0;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.