Concept explainers
(Conversions between Celsius and Fahrenheit) Write a class that contains the following two methods:
/** Convert from Celsius to Fahrenheit */
public static double celsiusToFahrenheit (double celsius)
/** Convert from Fahrenheit to Celsius */
public static double fahrenheitToCelsius(double fahrenheit)
The formula for the conversion is as follows:
fahrenheit = (9.0 / 5) * celsius + 32
celsius = (5.0 / 9) * (fahrenheit - 32)
Write a test
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Concepts Of Programming Languages
Management Information Systems: Managing The Digital Firm (16th Edition)
SURVEY OF OPERATING SYSTEMS
Starting Out With Visual Basic (8th Edition)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- 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 packagesarrow_forward(After reading the instructions given in the pictures attached, read the following) Class membersdoctorType Class must contain at least these functionsdoctorType(string first, string last, string spl); //First Name, Last Name, Specialty void print() const; //Formatted Display First Name, Last Name, Specialtyvoid setSpeciality(string); //Set the doctor’s Specialtystring getSpeciality(); //Return the doctor’s SpecialtypatientType Class must contain at least these functionsvoid setInfo(string id, string fName, string lName,int bDay, int bMth, int bYear,string docFrName, string docLaName, string docSpl,int admDay, int admMth, int admYear,int disChDay, int disChMth, int disChYear);void setID(string);string getID();void setBirthDate(int dy, int mo, int yr);int getBirthDay();int getBirthMonth();int getBirthYear();void setDoctorName(string fName, string lName);void setDoctorSpl(string);string getDoctorFName();string getDoctorLName();string getDoctorSpl();void…arrow_forwardUsing 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…arrow_forward
- (The Time class) Design a class named Time. The class contains: - The data fields hour, minute, and second that represent a time. - A no-arg constructor that creates a Time object for the current time. (The values of the data fields will represent the current time.) -A constructor that constructs a Time object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. (The values of the data fields will represent this time.) -A constructor that constructs a Time object with the specified hour, minute, and second. - Three getter methods for the data fields hour, minute, and second, respectively. -A method named setTime (long elapseTime) that sets a new time for the object using the elapsed time. For example, if the elapsed time is 555550000 milliseconds, the hour is 10, the minute is 19, and the second is 10. Draw the UML diagram for the class and then implement the class. Write a test program that creates two Time objects (using new Time (), new Time(555550000),…arrow_forwardNote: It`s python codingarrow_forward(The Account class) Account -id: int -balance: double -annualInterestRate : double -dateCreated : Date +Account( ) +Account(someId : int, someBalance : double) +getId() : int +setId(newId : int) : void +getBalance() : double +setBalance(newBalance : double) : void +getAnnualInterestRate( ) : double +setAnnualInterestRate(newRate : double) : void +getDateCreated( ) : Date +getMonthlyInterestRate( ) : double +getMonthlyInterest( ) : double +withdraw(amt : double) : void +deposit(amt : double) : void Design a class named Account that contains: ■ A private int data field named id for the account (default 0). ■ A private double data field named balance for the account (default 0). ■ A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. Make it static. ■ A private Date data field named dateCreated that stores the date when the account was created. (private Date dateCreated)…arrow_forward
- (Person Class) Design a class named Person that contains: o name, gender, and personCase as a private attribute o Non-default constructor that specifies name and gender o toString method that returns person data o personCase () method with no implementation (Student Class) Design a class named Student which is a child of Person that contains: o studentID as a private attribute o Nondefault constructor that specifies the name, gender, and studentID o toString method that returns student data o Implement personCase () that assigns "Not Studying" to personCase if studentID equals 0, “Studying" in case studentID greater than 0, and "Not a student" in case studentID less than 0. (Employee Class) Design a class named Employee which is a child of Person that contains: o employeelD as a private attribute o Non-default constructor that specifies the name, gender, and employeelD o toString method that returns employee data o Implement personCase () that assign “Technical" to personCase if…arrow_forwardwrite it in pythonarrow_forwardNeed help with part B the decode method AND the getChoice method using try/catch The program with the main method should be called ‘LetterCode.java’ The program with the class for performing the operations should be called LetterCodeLogic.java. The class should have two static methods: Encode and Decode (both of which receive a string parameter). Part A: The part A program will be the Encode function Part B: The Part B program will be the Decode function. This is my code so far for LetterCode.java: package lettercode; import business.LetterCodeLogic;import java.util.Scanner; /** * * @author Sean Jeffries */public class LetterCode { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int choice; String msg="", result=""; System.out.println("welcome to the Letter Code Program!"); choice = getChoice(); while (choice != 0) { switch (choice) { case 1: //encode…arrow_forward
- &8arrow_forwardQ-2) Given the following code: class Calculation { int z, public void addition(int x, int y) { z = x + y; System.out.println("The sum of the given numbers:"+z); } public void Subtraction(int x, int y) { z = x-y; System.out.println("The difference between the given numbers:"+z); public class My_Calculation extends Calculation { public void multiplication(int x, int y) { z = x*y; System.out.println("The product of the given c) Give the output when this program is run: numbers:"+z); } public static void main(String args[]) { int a = 20, b = 10; } My Calculation demo = new My_Calculation(); demo.addition(a, b); demo.Subtraction(a, b); demo.multiplication(a, b); Complete the missing lines in a and b a) Name the superclass the subclass b) Suppose we wish to save the program in a text file My_Calculation. The extension should be d) Which objects (variables and methods) are inherited from the superclass? e) If you instantiate demo as Calculation demo = new My_Calculation(); in the main…arrow_forwardPython Programming Questions (OOP): Question 2: i) Write a complete class called GasPump to represent a gas pump. The class should have a constructor to set the amount of available gas supply (in litres) and the price of gas per litre. The class should include: -An accessor and a mutator to set and get the gas price. -An accessor to get the current amount of gas supply. -A method to add fuel to the gas supply. Note that the maximum capacity of the pump is 5000 litres. If we try to add too much fuel, once the maximum capacity is reached, no more fuel can be added. -A method that sells a specific amount of gas. This method should reduce the supply of available gas by the amount sold and return the total cost of the gas sold. If the supply of the available gas is less than the amount requested, then only the existing supply should be sold. ii) Using the class defined in part (i), add a driver that will: - Create an object called ‘shell’ of the class GasPump and initializes it…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT