Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
Please help add a data validation (ex. let the user only input int) using exception handling
class Rectangle:
res = 0
res1 = 0
vol = 0
def __init__(self, length, width):
self.length = length
self.width = width
def perimeter(self):
self.res = 2 * ((self.length + self.width))
def area(self):
self.res1 = self.length * self.width
def display(self):
print("\n\nLength of a rectangle: ", self.length)
print("Width of a rectangle: ", self.width)
Rectangle.perimeter(self)
print("Perimeter of a rectangle: ", self.res)
Rectangle.area(self)
print("Area of a rectangle: ", self.res1)
class Parallelepipede(Rectangle):
def __init__(self, length, width, height):
super().__init__(length,width)
self.height = height
def volume(self):
self.vol = self.length * self.width * self.height
def display(self):
print("Height of a parallelepipede: ", self.height)
Parallelepipede.volume(self)
print("Volume of parallelepipede: ", self.vol)
if __name__ == "__main__":
length=eval(input("Length?: "))
width=eval(input("Width?: "))
height=eval(input("Height?: "))
r = Rectangle(length, width)
r.display()
p = Parallelepipede(length, width, height)
p.display()
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- A pedometer treats walking 2,000 steps as walking 1 mile. Write a stepsToMiles() method that takes the number of steps as an integer parameter and returns the miles walked as a double. The stepsToMiles() method throws an Exception object with the message "Exception: Negative step count entered." when the number of steps is negative. Complete the main() method that reads the number of steps from a user, calls the stepsToMiles() method, and outputs the returned value from the stepsToMiles() method. Use a try-catch block to catch any Exception object thrown by the stepsToMiles() method and output the exception message. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("%.2f", yourValue);arrow_forwardTrue or False We can define a custom generic exception.arrow_forwardPlease written by computer source Implement try/except exception handler to catch all errors (from the following source code) separately: my_string = 'Hello World' print(my_string) num = int(my_string) print(my_string + 100) num = 1/0 print(total) print('Done') Submission Instructions: 1. Write all the code in one module (in one .py file), and save it as Firstname_Lastname_hw6.py (e.g., John Adam’s file name should be John_ Adam_hw6.py).arrow_forward
- Instructions: Exception handing Add exception handling to the game (try, catch, throw). You are expected to use the standard exception classes to try functions, throw objects, and catch those objects when problems occur. At a minimum, you should have your code throw an invalid_argument object when data from the user is wrong. File GamePurse.h: class GamePurse { // data int purseAmount; public: // public functions GamePurse(int); void Win(int); void Loose(int); int GetAmount(); }; File GamePurse.cpp: #include "GamePurse.h" // constructor initilaizes the purseAmount variable GamePurse::GamePurse(int amount){ purseAmount = amount; } // function definations // add a winning amount to the purseAmount void GamePurse:: Win(int amount){ purseAmount+= amount; } // deduct an amount from the purseAmount. void GamePurse:: Loose(int amount){ purseAmount-= amount; } // return the value of purseAmount. int GamePurse::GetAmount(){ return purseAmount; } File…arrow_forward-Modify your parameter constructors to call your set methods. This will cause validation of the parameter.-Create an exception class named TractorException.-Modify your setters to throw TractorException if invalid values are passed in. You may also need to add a throws clause to your parameter constructors. This way we will not have any print methods in our Tractor object defining class-Modify your main method to try and catch exceptions. It should catch TractorExceptions and general Exceptions and display an appropriate message import java.util.*; class TestException { public static void main(String s[]) { Scanner scanner = new Scanner(System.in); boolean valid=false; // validation loop while (!valid) { try { System.out.println("Enter integer:"); int number = scanner.nextInt(); // may throw an exception System.out.println("You entered "+ number); valid=true;…arrow_forwardTime Converter 1. Write a program that converts dates from a numerical month-day format to alphabetic month-day format. IE 1/31 or 01/31 would have an output of January 31. 1. User enters the month and day as a single string. It is then converted. (10%) 2. Create 2 exception classes (20%) 1. MonthException thrown for invalid months 2. DayException-thrown for invalid days for the given month 3. You can assume Feb is always 28 days 2. This should run in a for loop and end when a user is done entering dates (70%)arrow_forward
- 1. Create an exception class called SocSecException. The UML diagram for this class is below. SocSecException + SocSecException(error: String) : The constructor will call the superclass constructor. It will set the message associated with the exception to "Invalid social security number" concatenated with the error string. 2. Create a driver program called SocSecProcessor. This program will have a main method and a static method called isValid that will check if the social security number is valid. SocSecProcessor + main(args : String[]): void + is Valid(ssn: String): boolean Copyright © 2019 Pearson Education, Inc., Hoboken NJ Task #2 Writing Code to Handle an Exception 1. In the main method: a. The main method should read a name and social security number from the user as String objects. b. The main method should contain a try-catch statement. This statement tries to check if the social security number is valid by using the method isValid. If the social security number is valid, it…arrow_forwardFirst, create the custom exception class called OutOfStockException by creating a new class that extends the Exception class The class has a single constructor that takes a single argument, a string called message. The message argument is passed to the parent class (Exception) via the super keyword. Create the Store class and import the java.util.HashMap and java.util.Map classes The Store class is defined with a private Map called products, which is used to store the product names and their corresponding quantities. Create a default constructor that initializes the products map with three items: "apple", "banana", and "orange", with respective quantities of 10, 5, and 0. Define thepurchase method , which takes two arguments: a product name and a quantity to be purchased. This method throws an OutOfStockException if either the specified product is not available in the store or if the requested quantity is greater than the quantity available in stock. The method first…arrow_forwardNote : Attempted in visual studio. Run the following code in Visual Studio and see if it generates an exception or not? If it generates an exception, then why is it doing so. Write the differences between static and dynamic objects as well. #include <iostream> using namespace std; class CRectangle { int width, height; public: void set_values (int, int); int area () {return (width * height);} }; void CRectangle::set_values (int a, int b) { width = a; height = b; } int main () { CRectangle a;// static object CRectangle* b=new CRectangle;//dynamic object a.set_values (1,2); b->set_values (3,4); cout << "*b area: " << b->area() << endl;//12 cout << "*b area: " << b->area() << endl;//12 delete b; cout << "*b area: " << b->area() << endl;//12 return 0; }arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education