class FractionType: def_init_(self, num, den): self.num = num self.den = den def_repr_(self): if self.den == 0: return "Cant divide by 0" else: return self.num,"/",self.den
Q: + empID: String firstName: String lastName: String payRate: Real Employee() SetEmpID(theID: String)…
A: Pseudocode Pseudocode is a crafted, informal communication that aids in the creation of algorithms…
Q: Scores Class Write a class named Scores which should have the following attribute: • _scores (a list…
A: Below is the required code in python and sample output:
Q: (Person Class) Design a class named Person that contains: o name, gender, and personCase as a…
A: In this question we have to program the java classes for Persons, Employee and student class where…
Q: Temp Class - Create Temp class whos job is to hold a temp in degrees F and gives methods to get the…
A: Actually, Java is a high level programming language. And also object oriented .It. Is a platform…
Q: (Stopwatch) Design a class named StopWatch. The cl Private data fields startTime and endTime with A…
A: I have solved the question below:
Q: True or False In structs, all fields and methods are public i.e. all the data can be accessed and…
A: There are multi types of access modifiers like :- public, protected and private. In struct, if all…
Q: Rectangle Object Monitoring Create a Rectangle class that can compute the total area of all the…
A: import java.io.*; import java.util.*;public class Main{ public static void main(String[] args) {…
Q: Assignment Tasks In a Java program • Create a class named "Car" The class must have the following…
A: Code: import java.util.Scanner; class Car{ String carID,Brand; boolean isItElectricCar; double…
Q: Modify the Item class to maintain a priority value. This value must also be set in the constructor.…
A: The given class has been modified as per the requirement.
Q: Encapsulations accessor/mutator Method overloading Objects as parameters Objects as return type
A: Program Approach: In the given code two-class "Aeroplane and Airport" is declared that uses its…
Q: . Class Account Instance variables: private int accountId; //Auto increment private String…
A: First, we create an Account class with the following attributes: 1. Class AccountInstance…
Q: The class name is Exam with three private data members: exam course code (String), exam score…
A: public class Main{ public static void main(String[] args) { Exam e=new…
Q: Design a class named StopWatch. The class contains:■ The private data fields startTime and endTime…
A: UML diagram for class :
Q: 1. Pet Class Write a class named Pet, which should have the following data attributes: • _ _name…
A: class Pet: def __init__(self, name = "", animal_type = "", age = 0): self.__name = name…
Q: (Geometry: the Circle2D class) Define the Circle2D class that contains: 1 Two double data fields…
A: The question is to write a code for the given problem. As no language has been specified, here C++…
Q: Pet Class Design a class named Pet, which should have the following fields: name: The name field…
A:
Q: Question (see pic) Code: (see question below the code): class Document: #TO DO: define the…
A: Given: Question (see pic) Code: (see question below the code): class Document: #TO DO: define…
Q: Personal Information Class: Design a class called Employee that holds the following data about an…
A: from employee import Employee name = input("Enter employee name: ")idd = input("Enter employee ID:…
Q: Create a class Rectangle. The class has attribute length and width, each of which defaults to 1. It…
A: public class Rectangle { double length; double width; public Rectangle() { this.length = 1;…
Q: User Class ATTRIBUTES NOTE: The important method has been given to you. userld:int //generates…
A: Class is a user-defined data type that can store the different types of the data values like…
Q: (Savings Account Class) Create class SavingsAccount. Use a static variable annualInterestRateto…
A: Java programs for the given criteria is as follows, File name: “SavingsAccount.java” //Create a…
Q: 1. Quiz Grade a) There are six quizzes with grades 0 through 10. The lowest grade will be dropped.…
A: File name: "quizzes.py" class Quizzes: def __init__(self, grades): self.grades = grades…
Q: C++ Create a class Rectangle. The class has attributes length and width, each of which defaults to…
A: The , code has given below:
Q: python Cylinder class: Instance variables: Make instance variables appropriately to accomplish the…
A: Python used to answer this question
Q: 1. Pet Class Write a class named Pet, which should have the following data attributes: • _ _name…
A: class Pet: def __init__(self, name = "", animal_type = "", age = 0, color = ""):…
Q: Write a class Travel having two private data members (distanceCovered , Time) The class has three…
A: public class Box{ //declaring data members private double width; private double depth; private…
Q: Focus on classes, objects, methods and good programming style Your task is to create a BankAccount…
A: The program is: #include<iostream>#include<stdio.h>#include<string.h>using…
Q: gender: char courses: Course[] int: nbOfCourscs + Student( sid: int, sname: String) +…
A: Solution: Note: Please give a thumbs up if you like it. Given,
Q: Q No#1 (Area Class) Write a program to print the area of a rectangle by creating a class named…
A: A class is a user-defined data type that combines data members and methods for manipulating that…
Q: Focus on classes, objects, methods and good programming style Your task is to create a BankAccount…
A: import random #to get random intergerclass BankAccount: #define class def…
Q: Nutritional information (classes/constructors) PYTHON ONLY Complete the FoodItem class by adding a…
A: Given: Complete the FoodItem class by adding a constructor to initialize a food item. The…
Q: tance data: Variable mpg for fuel efficiency (miles per gallon = mpg) Variable gas to save how many…
A: We need to implement the Vehicle class and Main.java as per the given requirements.
Q: Rules: Corner cases. By convention, the row and column indices are integers between 0 and n − 1,…
A: Unit testing. Your main() method must call each public constructor and method directly and help…
Q: following class. Complete the statement inside every mutator and accessor based on the following…
A: Here we have given code for the given problem . You can find the solution in step 2.
Q: 1. Employee Class Write a class named Employee that has the following fields: • name. The name field…
A: import java.util.*;import java.lang.*;import java.io.*; class Employee{ //fields String name; int…
Q: da int noofElements; float avg; public: // define necessary getter and setter method (s) // define…
A: main.cpp #include <iostream> using namespace std; class Array { int *dataPtr; // stores…
Q: Class Quiz public Quiz (int quesList, int quesMissed) { quesList = this.quesList; quesMissed =…
A: To use scoreQuiz in passFailQuiz() method. Create getScoreQuiz() method. public int getScoreQuiz() {…
Q: • having no parameter – for setting values to zero or null. • having two parameters for assigning…
A: Algorithm: First we declare the class and default contructor Overload default constructor with a…
Q: Start Class: Banking System - accname: string - balance: double = 0; -pin: int - userpin: int…
A: Flowchart is the diagrammatic representation of the process or action. In flowchart action is…
Q: A. Build a class named car. This class is defined as follows: It has the fields: Car ID, Car model,…
A: Solution: Given,
Q: class Parent: # docstring, def method(self) -> None: "*"A method that differs for each of the child…
A: The Answer is
Q: Hands-on Activity People in School Objective: At the end of the activity, the students should be…
A: In the question given above, the UML diagram for the class Faculty doesn't include any setter method…
Q: Pet Class Design a class named Pet, which should have the following fields: name: The name field…
A: Exрlаnаtiоn:I hаve written the соde fоr the Рet сlаss аnd РetРrоgrаm сlаss tо shоw the…
Q: (Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which…
A: The class Rectangle is created as follows: The two attributes are length and width of double type.…
Q: C. Video class inherits the class Disk. It has as attributes two Strings director and description.…
A: Given :
Q: (The MyDate class) Design a class named MyDate. The class contains: The data fields year, month, and…
A: Note : since programming language is not mentioned we are providing solution in java programming.…
Q: Object Oriented Programming in JAVA Define and use a class for the student record. The class…
A: Define the class Student for storing the student record. Create attributes for storing the quizzes,…
Q: Personal Information Class: Design a class called Employee that holds the following data about…
A: According to the information given:- We have to follow the instruction in order to get desired…
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
I am trying to use this code under __repr__ to write an error when someone inputs a 0 as the denominator but it isn't working. What can i do to fix this?
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- (Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. THIS IS C#Modify the Item class to maintain a priority value. This value must also be set in the constructor. private int num; public Item(int num) { this.num = num; } public int GetNum() { return num; }Temp Class - Create Temp class whos job is to hold a temp in degrees F and gives methods to get the temp in F, Celsius, and Kelvin. The class should follow the instance variable (field): ftemp (double type that holds F temp)Follow these methods with the class.. Constructor --Will accept Fahrenheit temperature as a double to store it in the ftemp field. setFahrenheit - The setFahrenheit method accepts a Ftemperature as a doubleto stores it in the ftemp field. getFahrenheit - Returns the value of the ftemp field, as a Fahrenheit temperature (no conversion required). getCelsius - Returns the value of the ftemp field converted to Celsius. [C e l s i u s = ( 5.0 / 9.0 ) × ( F a h r e n h e i t − 32 )] getKelvin - Returns the value of the ftemp field converted to Kelvin. [K e l v i n = ( ( 5.0 / 9.0 ) × ( F a h r e n h e i t − 32 ) ) + 273] Exemplify the temp class by writing a (test) program that is separate and promotes users for an F Fahrenheit temp. The program must create an…
- Nutritional information (classes/constructors) PYTHON ONLY Complete the FoodItem class by adding a constructor to initialize a food item. The constructor should initialize the name (a string) to "None" and all other instance attributes to 0.0 by default. If the constructor is called with a food name, grams of fat, grams of carbohydrates, and grams of protein, the constructor should assign each instance attribute with the appropriate parameter value. The given program accepts as input a food item name, fat, carbs, and protein and the number of servings. The program creates a food item using the constructor parameters' default values and a food item using the input values. The program outputs the nutritional information and calories per serving for both food items. Ex: If the input is: M&M's10.034.02.01.0 where M&M's is the food name, 10.0 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 1.0 is the number of servings, the output is:…Circle ClassWrite a Circle class that has the following fields:• radius: a double• PI: a final double initialized with the value 3.14159The class should have the following methods:• Constructor. Accepts the radius of the circle as an argument.• Constructor. A no-arg constructor that sets the radius field to 0.0.• setRadius. A mutator method for the radius field.• getRadius. An accessor method for the radius field.• area. Returns the area of the circle, which is calculated asarea = PI * radius * radius• diameter. Returns the diameter of the circle, which is calculated asdiameter = radius * 2• circumference. Returns the circumference of the circle, which is calculated ascircumference = 2 * PI * radiusWrite a program that demonstrates the Circle class by asking the user for the circle’s radius, creating a Circle object, and then reporting the circle’s area, diameter, and circumference.Exercise 1-Account class • Design a class named Account that contains : • A private int data field named id for the account • A private double data field named balance for the account • A privet Date data field named dateCreated that stores the date when the account was created • A no-arg constructor that creates a default account • A constructor that creates an account with the specified id and initial balance • The getters (i.e., accessors) and setters (i.e., mutators) methods for id and balance • The getter method for dateCreated • A method named withdraw that withdraws a specified amount from the account • A method named deposit that deposits a specified amount to the account
- 7)Circle Class Write a Circle class that has the following fields: radius: a double PI:a final double initialized with the value 3.14159 The class should have the following methods: Constructor. Accepts the radius of the circles as an argument. Constructor. A no-arg constructor that sets the radius field to 0.0. setRadius. A mutator method for the radius field. getRadius.An accessor method for the radius field. area. Returns the area of the circle, which is calculated as area. Returns the area of the circles, which is calculated as area= PI * radius * radius diameter. Returns the diameter of the cirlce, which is calculated as diameter = radius * 2 circumference. Returns the circumference of the circle, which is calculated as circumference = 2 * PI * radius Write a program that demonstrates the Circle class by asking the user for the circles's radius, creating a Circle object, and then reporting the cirlce's area, diameter, and circumference.Class Quiz public Quiz (int quesList, int quesMissed) {quesList = this.quesList;quesMissed = this.quesMissed;} private void calculate(){// get the point worth of each question and calculate final scorepointsPerQues = (100/quesList);scoreQuiz = quesList - quesMissed;} Class PassFailQuiz public PassFailQuiz (int quesList, int quesMissed, int scoreQuiz) { super(quesList, quesMissed);} How do I move scoreQuiz from private void calculate() to equal the third constructor value in PassFailQuiz?Car ClassWrite a class named Car that has the following fields:• yearModel. The yearModel field is an int that holds the car’s year model.• make. The make field references a String object that holds the make of the car.• speed. The speed field is an int that holds the car’s current speed. In addition, the class should have the following constructor and other methods.• Constructor. The constructor should accept the car’s year model and make as arguments. These values should be assigned to the object’s yearModel and make fields. The constructor should also assign 0 to the speed field.• Accessors. Appropriate accessor methods should get the values stored in an object’s yearModel, make, and speed fields.• accelerate. The accelerate method should add 5 to the speed field each time it is called.• brake. The brake method should subtract 5 from the speed field each time it is called.Demonstrate the class in a program that creates a Car object, and then calls the accelerate method five…
- Book Donation App Create a book-app directory. The app can be used to manage book donations and track donors and books. The catalog is implemented using the following classes: 1. The app should have donors-repo.js to maintain the list of donors and allow adding, updating, and deleting donors. The donor object has donorID, firstName, lastName, and email properties. This module should implement the following functions: • getDonor(donorId): returns a donor by id. • addDonor(donor): adds a donor to the list of donors; donorID should be autoassigned a random number. • updateDonor(donor): updates the donor having the matching donorID. • deleteDonor(donorID): delete the donor with donorID from the list of donors, only if they are not associated with any books. 2. The app should have books-repo.js to maintain the list of donated books and allow adding, updating, and deleting books. The book object has bookID, title, authors, and donorID properties. • donorID references the book’s donor. This…Java Instance data:Variable mpg for fuel efficiency (miles per gallon = mpg)Variable gas to save how many gallons of gas left in the tank Constructors:Default constructor with no parameter. Use 0 as initial values.Overloaded constructor with two parameters Methods:getMPG() & setMPG()(getGas() & setGas()toString() methoddrive() to simulate that the car is driven for certain miles. For example, v1.drive(100) means vehicle v1 is driven 100 miles. You need to calculate the gas cost and update the gas tank: gas = gas - miles/mpg. You also need to check if there is enough gas left since gas should not be negative. You need to figure out the formal parameters for the above methods. In the testing class, prompt the user for information to create two objects of the Vehicle class. Let each vehicle drive 200 miles. Print out the left gas for each vehicle. Ex: Vehicle 1 Enter the mpg: 40 Enter the gas left: 10.5 Vehicle 2 Enter the mpg: 35 Enter the gas left: 2.1 Vehicle 1…JAVA Language Caesar Shift Question: Modify the Caesar class so that it will allow various sized shifts to be used, instead of just a shift of size 3. (Hint: Use an instance variable in the Caesar class to represent the shift, add a constructor to set it, and change the encode method to use it.) import java.util.*; public class TestCipher { public static void main(String[] args) { int shift = 7; Caesar caesar = new Caesar(); String text = "hello world"; String encryptTxt = caesar.encrypt(text); System.out.println(text + " encrypted with shift " + shift + " is " + encryptTxt); } } abstract class Cipher { public String encrypt(String s) { StringBuffer result = new StringBuffer(""); // Use a StringBuffer StringTokenizer words = new StringTokenizer(s); // Break s into its words while (words.hasMoreTokens()) { // For each word in s…