Please give the code without errors
HELLO!!
EXPLANATION:
CODE:
import java.util.Scanner; //importing Scanner class
class Person //super class
{
String name; //declaring variables
Person(String s){ //constructor to assign values to the variables
name=s;
}
}
class Doctor extends Person //sub class
{
String specialty; //attributes
double fee;
Doctor(String s1,String sp,double f) //constructor assing values to the attributes
{
super(s1); //calling the super class constructor and passing a string parameter
specialty=sp;
fee=f;
}
void setFee(double f1) //a setter method
{
fee=f1;
}
double getFee() //a getter method
{
return fee;
}
public String toString(){ //to string method
return (name+" "+specialty+" "+fee);
}
}
class DoctorTest //class with main method
{
public static void main(String args[]){
Scanner sc=new Scanner(System.in); //instance to scanner class
System.out.println("Enter the doctors name: ");
String n1=sc.next(); //promts the user to enter
System.out.println("Enter the doctor's specialty: ");
String n2=sc.next(); //promts the user to enter
System.out.println("Enter office visit fee: ");
double f1=sc.nextDouble(); //promts the user to enter
Doctor d=new Doctor(n1,n2,f1); //object creation
System.out.println(d.toString()); //prints the return of tostring method
d.setFee(f1); //calling setFee method
System.out.println("Doctor's fee is: "+(d.getFee()));//printing the return of getFee method
}
}
OUTPUT:
Please give the code without errors Define a class named Doctor whose objects are records for...
Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...
Code the following Program in C++ Define a class named Payment that contains a member variable of type float that stores the amount of the payment and appropriate accessor and mutator methods. Also create a member function named paymentDetails that outputs an English sentence that describes the amount of the payment. Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails function to indicate that the payment is in cash. Include appropriate constructor(s)....
Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you are expected to implement in your Shape class; - A private String color that specifies the color of the shape - A private boolean filled that specifies whether the shape is filled - A private date (java.util.date) field dateCreated that specifies the date the shape was created Your Shape class will provide the following constructors; - A two-arg constructor that creates a shape with...
// Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...
java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...
Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define a variable xVar (type: char, value: 65), and a method myPrint to print xVar. SubClass is a subclass of BaseClass. In SubClass, define a variable yVar (type: int, value: 16) and another variable strVar (type: String, value: "java program!"). There is also a method myPrint to print the value of yVar and strVar in SubClass, as well as an additional method printAll, in which...
Programming Assignment 1 Write a class called Clock. Your class should have 3 instance variables, one for the hour, one for the minute and one for the second. Your class should have the following methods: A default constructor that takes no parameters (make sure this constructor assigns values to the instance variables) A constructor that takes 3 parameters, one for each instance variable A mutator method called setHour which takes a single integer parameter. This method sets the value of...
Your will write a class named Gasket that can be used to build Gasket objects (that represent Sierpinski gaskets) that you can display graphically. Your Gasket class is defined in the provided file Gasket.h. DO NOT CHANGE the file Gasket.h. The attributes and methods defined for class Gasket are described below. ·sideLength an int that holds the length of each side of the Gasket. The length of the side is measured as a number of pixels ·xLocation an int that holds the x coordinate (in pixels)...
In Java please! Problem You will be using the point class discussed in class to create a Rectangle class. You also need to have a driver class that tests your rectangle. Requirements You must implement the 3 classes in the class diagram below and use the same naming and data types. Following is a description of what each method does. Point Rectangle RectangleDriver - x: int - top Left: Point + main(args: String[) - y: int - width: int +...
*** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...