Problem Description: Write a class Battery that models a rechargeable battery. A battery has a constructor public Battery(double capacity) where capacity is a value measured in milliampere hours. A typical AA battery has a capacity of 2000 to 3000 mAh. The method public void drain (double amount) drains the capacity of the battery by the given amount. The method public void charge () charges the battery to its original capacity. The method public double getRemainingCapacity () gets the remaining capacity of the battery.
Q: Write a program using method overloading and constructor overloading to do the following tasks. a)…
A: public class Speed { //declaring variables private double U; private double A; private double K;…
Q: 2. Create a SavingsAccount class that behaves just like a BankAccount, but also has an interest rate…
A: Code: class SavingAccount{ private double interestRate; private double balance; public…
Q: 4. Create an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle…
A: Solution: Given,
Q: Design a class that holds the following personal data: name, address, age, and phone number. Write…
A: The required Python code: class Person: def __init__(self, name, address, age, phone): #…
Q: Write a program using method overloading and constructor overloading to do the following tasks. a)…
A: Given:
Q: CLASS AND OBJECT WRITE! 1.) Write the main class of the given class Animal below that set the…
A: Step 1:- Program Approach:- 1.Create the object of the class Animal 2.call the function…
Q: Write a java program in which Animal: Create a class Animal and Add a protected data member named…
A: public abstract class Animal { protected int id; //default constructor public Animal() { this.id…
Q: Define a class called Country. A Country has populationSize, area, capital, currency, and…
A: Given: Define a class called Country. A Country has populationSize, area, capital, currency, and…
Q: Create a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and…
A: The question asks about constructing a super class of BeautyProduct and then two child classes for…
Q: Two dogs are considered “equal” if they have the same sound. Give the code for the equals(...)…
A: Below is the answer with explanation:
Q: Write a class HouseBuilder with private class members as houseArea(double, e.g. 20 square feet),…
A: abstract class HouseBuilder{ protected double houseArea; protected String houseLocation;…
Q: Create a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and…
A: Create three classes : BeautyProduct , Lipstick and Foundation. Then create main function which…
Q: You are asked to write a discount system for a beauty saloon, which provides services and sells…
A: Now lets see the classes from package com.java.discountsystem.constantDiscountRate.java package…
Q: write a java program This composition example contains classes Date, Employee and EmployeeTest…
A: Given: Class EmployeeTest creates two Date objects to represent an Employee’s birthday and hire…
Q: Part (1) Define a class as follow: a. create a class called Student that has four instance variables…
A: The program is written in Java. Please check the source code and output in the following steps.
Q: 5. Create an abstract class Pen with methods write () and refill () as abstract methods. Now, use…
A: A class which contains the abstract keyword in its declaration is known as abstract class. Abstract…
Q: Overloading is achieved when two or more methods in the same class have the same
A: Method overloading or function overloading means creating methods with same name but different…
Q: Create a Dog and a Cat class, each of which inherit from Animal. Each class should have a…
A: Programs are a set of lines of code that give the machine instructions. To complete those tasks,…
Q: Python program for this project: Patient Charges Write a class named Patient that has attributes…
A: class Patient: Firstname = "" Middlename = "" Lastname = "" Address = "" City = ""…
Q: hen: 1) Add a public class constant which set the maximum area to 40.0 2) Add another constructor…
A: Algorithm: Start Create a class Room with attributes WindowNum,length,width Initialize a constant…
Q: You are asked to write a discount system for a beauty saloon, which provides services and sells…
A: PROGRAM INTRODUCTION: Import the required libraries. Start definition of customer class. Declare…
Q: Java always provides a default constructor. That is, a constructor that can be caller with no…
A: We have to explain whether this statement is true or false. Java always provides a default…
Q: java
A: import java.io.*;import java.util.*; public class Encapsulatoin2{ //Member Variables private int…
Q: A SuperDie Class Write a class SuperDie that models a single die with an arbitrary number of sides,…
A: Along with main method, there will be default constructor, parameterized constructor, getter and…
Q: and assign to it the average number of yards Barkley has gained per carry. This line of code (3) On…
A: Below is the required code and sample output:
Q: Given the following statement: Paper paper = new Paper("A4", 80); where "A4" is the paper size and…
A: Step 1st: Private Attributes of papersize and paperweight; Step 2nd: Constructor of Paper class Step…
Q: static methods are copied into each object that's produced. accurate or incorrect
A: The above statement is an incorrect Explanation : Static methods are the methods in Java that can…
Q: Define a class called Country. A Country has population S ize, area, capital, currency, and…
A: the required code is
Q: Create a class called RoomCarpet that has three private instance variables – room length and width…
A: Create a Java class that has the private double data of length, width, and price. Create the gets…
Q: Suppose that the class Pet has a field called name that is of the type String. Write an assignment…
A: public Pet(String petsName) { } This is the constructor of class Pet. It accepts one argument of…
Q: Write a function that overwrite the greater than method for a class. The class has a field variable…
A: Given, The function to be implemented should overwrite greater than,and it has to implement less…
Q: Write a class encapsulating the concept of the weather forecast, assuming that it has the following…
A: Since programming language is not mentioned in the question, we will answer this question in the…
Q: Determine the difference between a constructor and a method.
A: Given: Determine the difference between a constructor and a method.
Q: Design a class called circle which contains: -Two instance variables: radius (type double) and color…
A: As per our company guidelines, we are supposed to answer only one question per post and kindly…
Q: The BankAccount class described below is used to represent a personal savings account with a yearly…
A: ALGORITHM:- 1. Create a class CreditAccount inheriting the BankAccount class. 2. Override the…
Q: same function which prints "Rectangle is a polygon" and "Triangle is a polygon" respectively. Again,…
A: Given : Same function which prints "Rectangle is a polygon" and "Triangle is a polygon"…
Q: Question 7 Design the Programmer class such a way so that the following code provides the expected…
A: class Programmer: name = "" language = "" experience = 0 #Constructor def…
Q: The following code is in Java: public class Vehicle // Superclass { private…
A: Given code snippet in java public class Vehicle // Superclass { private double cost;…
Q: Write a class Battery that models a rechargeable battery. A battery has a constructor
A: public class BatteryTester{ public static void main (String[] args) { Battery battery=new…
Q: Find the error(s) in the following class definition: public class TestClass { private int value1;…
A: answer along with screenshots are given below
Q: Consider the following Student Class An. EngineeringStudent "is-a" Student whose major is…
A: EngineeringStudent is a student whose major is Engineering. Therefore this class needs to extend the…
Q: Write only the appropriate classes definition for described below: Let's consider class Employee's.…
A: public class Employee{ //declaring instance variables private String firstName; private…
Q: The class Thingy is defined as shown below. public class Thingy { private int stat; public…
A: Required: To run the code and determine the output. code and screenshot are in the next step with…
Q: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
A: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
Q: 7. Consider the following design for a Product class that keep track of product inventory: public…
A: public class Product { public Product(String name, double qty) { prodName = name;…
Q: 7. Consider the following design for a Product class that keep track of product inventory: public…
A: public class Product { public Product(String name, double qty) { prodName = name;…
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- # Coding - Simulate a robot Write a program that simulates the movements of a robot. The robot can have three possible movements: turn right turn left advance The robot is placed on a hypothetical infinite grid, facing a particular direction (north, east, south, or west) at a set of `{x,y}` coordinates,e.g., `{3,8}`, with coordinates increasing to the north and east. Create a Class `Robot` that contains a method `execute` which given a number of instructions will calculate the robot's new position, and the the direction in which it is pointing. ## Example The letter-string "RAALAL" means: Turn right Advance twice Turn left Advance once Turn left yet again Say a robot starts at `{7, 3}` facing north. Running this stream of instructions should leave it at `{9, 4}` facing west. ## Inputs and Outputs The argument of the `execute` is `string` in the format `X Y BEARING COMMANDS`. The method should return a one-liner `string` in the format `X Y BEARING`. In the…phys2 - Google Drive Books ▾ WhatsApp Study Career Life 9.6 (Stopwatch) Design a class named StopWatch. The class contains: Private data fields startTime and endTime with getter methods. ■ A no-arg constructor that initializes startTime with the current time. ■ A method named start() that resets the startTime to the current time. ■ A method named stop() that sets the endTime to the current time. ■ A method named getElapsedTime) that returns the elapsed time for the stopwatch in milliseconds. Show transcribed image text Draw the UMI. diagram for the class and then implement the class. Write a test program that measures the execution time of sorting 100,000 numbers using selection sort. For edUsing JAVA Part A) Design a class Message that models an e-mail message. A message has a recipient, a sender, and a message text. Support the following methods: 1) A constructor that takes the sender and recipient. 2) A method append that appends a line of text to the message body A method toString that makes the message into one long string like: “From: Harry Morgan%nTo: Rudolf Reindee%n . . . “ Write a program that uses this class to make a message and print it. Part B) Design a class Mailbox that stores e-mail messages, using the Message class in part a) Implement the following methods in the Message class. public void addMessage(Message m) // Adds Message M to the Mailbox public Message getMessage(int i) // returns the ith message from the Mailbox public void removeMessage(int i) // removes the ith message from the Mailbox public int mailBoxSize () // returns the number of messages in the Mailbox Write a program to demonstrate the functionality of the Mailbox. Add messages to…
- Classes and Objects) Hand-write a complete Java class that can be used to create a Car object as described below. a. A Vehicle has-a: i. Registration number ii. Owner name iii. Price iv. Year manufactured b. Add all instance variables C. The class must have getters and setters for all instance variables d. The class must have two constructors, a no-args and a constructor that receives input parameters for each instance variable.Instructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and…Language is Java Write a Clothing class with the following attributes: color (e.g., "blue", "green", "orange") displayName (e.g., "Doctor Who hoodie", "slacks") price (e.g., 19.99, 7) Include only one constructor. It should have parameters for each of the attributes and set their values. Additionally, include getters and setters for each of the attributes. Add a driver, name it Purchases, and create 2 Clothing objects. Finally, print out some information about both objects (i.e., print the information from some or all of the getters). For example, if you created a Clothing object whose color was blue, whose display name was work trousers, for a price of 27.99, you could use the getters to print something like this:These work trousers are blue and cost $27.99.Don't hardcode the print statement for full credit, you must use the getters
- ** StopWatch class ** Often, we need to determine how long it takes/took to perform a certain action(s). Write a class, StopWatch which will provide an easy interface to the computer's timing facilities. When you first create a Timerobject, it should be set to a 'stop' state. When the programmer wants to time something, they call the start) method before the action executes and call the stop) method after the event finishes. The elapsed) method will return (in whole seconds) how long the action took. This simple operation may not suit all programmers' needs. To allow more general usage, we'll also the programmer to start the timer at the object's declaration. Also, a programmer can get the elapsed time whether the timer is still running or not. Finally, we'll provide an toString() method so the programmer can directly print the currently elapsed time without having to retrieve it separately. In addition, allow the programmer to subtract) and add0 two StopWatch objects to receive a…Exercise: 1) Design a class ComboLock that works like the combination lock in a gym locker, as shown below. The lock is constructed with a combination-three numbers between 0 and 39. The reset method resets the dial so that it points to 0. The turnLeft and turnRight methods turn the dial by a given number of ticks to the left or right. The getStatus method returns a Boolean indicating whether the lock is opened(true) or closed(false). The lock opens if the user first turned it right to the first number in the combination, then left to the second, and then right to the third. 02 36 2) Document your class. 3) Provide a tester class and test a scenario in which you create a comboLock having the code (25, 36, 19), unlock it successfully, and print the status of the lock after each turn. 4) Put the ComboLock class and the tester class in two distinct packages· Exercise # 2: Implement a class Portfolio. This class has two objects, checking and saving, of the type bankAccount that was developed in the worked example. Initialize the 2 bank accounts with 0 initial balance. . Implement four methods • def deposit (self, amount, account) • def withdraw (self, amount, account) • def transfer (self, amount, account) • def getBalance (self, account) • Here the account string is "S" or "c" for Saving and Checking, respectively. For the deposit or withdraw, it indicates which account is affected. For a transfer, it indicates the account from which the money is taken; the money is automatically transferred to the other account. • To test your class: . create one Potfolio object • deposit 10000 in its checking account . transfer 5000 from checking account to saving account . withdraw 2500 from checking account display the balance of both accounts • A run for the above test program will result in the following output 5000.0 Saving balance = Checking…
- JAVA-Homework Write a Java program to create Human as a class with Hpersonname and Hpersonage as members of class HUman, and can make employee and Lecturer as the subclasses of Human (a class can have any number of subclasses). In the employee class, we can define grade member and in the Lecturer class also income member will be defined. 1. The program must be able to store information about employee and Lecturer. we want to store the Hpersonname and Hpersonage with grade of employee and the Hpersonname and Hpersonage with income of lecturer.:Define and implement class Employee. This class should contain the following fields: first name, last name, employee id, hourly pay. This class should contain getters and setters for all its attributes. This class also needs at least one constructor. Implement method computePay() in this class. This method should accept an integer number of hours the employee worked as an input argument and return a floating point value indicating the pay the employee earned. If the number of hours is invalid (e.g. a negative number) this method should throw NumberFormatException. If the number of hours is over 40 then this method should throw a custom exception named TooManyHoursWorkedException. Remember that you will have to define your own exception class for this. Save this class and its definition into a file named Employee.java. Define and implement class EmployeeTest.This class should implement main() method. In the body of the main() method you should create an instance of Employee with the…public class date { private int day; // from 1 to 31 private int month; // from 1 to 12 private int year; // from 2000 upwards public void advance (); // move to next day }; Implement a constructor that initializes new objects of date class to be set to the 1st of January 2000. Implement setters for day, month, and year. Implement the advance method, which moves to the next day, ensuring that all data members are updated appropriately.