/*C sharp program that demonstrates the Prism and Square
classes
in the below Program.cs .*/
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise
{
class Program
{
static void Main(string[] args)
{
//declare variables of double type
double volume;
double height;
//try-catch block
try
{
//Crate a Prism class object
Prism p1=new Prism();
//Set Volume and Height to 10 and 0
p1.Volume=10;
p1.Height =0;
//check if height is 0 then throw exception
if (p1.Height ==0)
throw new DivideByZeroException ();
}
//catch exception
catch (DivideByZeroException exp)
{
Console.WriteLine(exp.Message);
Console.WriteLine ("You tried to divide by zero which is
impossible");
}
//try-catch block for Square
class
try
{
//Crate a Square class object
Square s1 = new Square();
Console.Write("Input value for the volume>>>");
//Convert the string to double
volume = Convert.ToDouble(Console.ReadLine());
//Set volume
s1.Volume = volume;
Console.Write("Input value for the height>>>");
//Convert the string to double
height = Convert.ToDouble(Console.ReadLine());
//Set Height
s1.Height = height;
}
//catch exception for invalid user input
catch (Exception exp)
{
Console.WriteLine("You tried to input string instead of
number");
}
Console.ReadLine();
}
}
}
------------------------------------------------------------------------------------------
//Prism.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise
{
class Prism
{
private double height;
private double volume;
//Default Constructor
public Prism()
{
Height = 1;
Volume = 1;
}
//Constructor
public Prism(double _height, double _volume)
{
Height = _height ;
Volume = _volume;
}
//Height property
public double Height
{
set{ height = value; }
get{ return height ; }
}
//Volume property
public double Volume
{
set { volume = value; }
get { return volume; }
}
//Calculate area
public double CalcArea()
{
double area = 0;
area = volume / height;
return area;
}
} //end of the Prism class
}
------------------------------------------------------------------------------------------
//Prism.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise
{
class Square : Prism
{
private double length;
private double area;
//Default constructor
public Square()
{
length = 0;
area = 0;
}
//Area property
public double Area
{
set { area = CalcArea(); }
get { return area; }
}
//Length property
public double Length
{
set { length = value ; }
get { return length; }
}
/*Return area of the square */
public double CalcArea()
{
return length * length;
}
}
}
-------------------------------------------Sample Output------------------------------------------------------------------
Write the C# code and make a screenshot of the output according to tasks given below:...
Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....
Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String input =""; System.out.println("Welcome to the easy square program"); while(true) { System.out.println("Enter the length of the side of a square or enter QUIT to quit"); try { input = keyboard.nextLine(); if(input.equalsIgnoreCase("quit")) break; int length = Integer.parseInt(input); Square s = new Square(); s.setLength(length); s.draw(); System.out.println("The area is "+s.getArea()); System.out.println("The perimeter is "+s.getPerimeter()); } catch(DimensionException e)...
Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...
PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...
Please help with a source code for C++ and also need screenshot of output: Step 1: Create a Glasses class using a separate header file and implementation file. Add the following attributes. Color (string data type) Prescription (float data type) Create a default constructor that sets default attributes. Color should be set to unknown because it is not given. Prescription should be set to 0.0 because it is not given. Create a parameterized constructor that sets the attributes to the...
Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...
Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...
Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...
Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO MAKE SURE IT IS WRITTEN IN C++! thank you so much in advance and I will upvote when done right! (26 points total) Write an inheritance hierarchy for classes of simple shapes. 1. Create a class Shape. Derive the class ThreeDimensionalShape from the Shape class. Derive the class Sphere from the ThreeDimensionalShape class Use abstract classes to define Shape and ThreeDimensionalShape classes, and then...
Please provide the full code...the skeleton is down below: Note: Each file must contain an int at the beginning, stating the number of records in the file. Afterwards, the number of records in the file will follow. Each record that follows will consist of a last name (String), and a gpa (double). However, to test the error handling of your program, the number of records will not always match the int value. All possible combinations should be tested. 1.) Prompt...