Question

In: Computer Science

//Question1: What is the name of the following lines in the data type class? private int...


//Question1: What is the name of the following lines in the data type class? private int intVariable;
private float floatVariable;
private String stringVariable;

//Question2: What is the name of the following lines in the data type class? public DataTypeClass_Smith()
{
intVariable = 0; floatVariable = 0.0; stringVariable = “aString”;
}

//Question3: What is the name of the following lines in the data type class? public DataTypeClass_Smith( int intVar, float floatVar, String stringVar)
{
intVariable = intVar; floatVariable = floatVar; stringVariable = stringVar;
}

//Question4: What is the name of the following method in the data type class? public void setIntVariable(int intVar)
{
intVariable = intVar; }


//Question5: What is the name of the following method in the data type class? public float getFloatVariable(0
{
return floatVariable;


//Question6: What is the purpose of the following method in the data type class? public String toString()
{
String str = “My name: James Smith\n” + “The output is: \n” +
“Integer number: “ + intVariable + “\n” + “Decimal number: “ + floatVariable + “\n” + “String is: “ + stringVariable + “\n”;
return str;
}

Solutions

Expert Solution

Question1 answer:

intVariable,floatVariable,stringVariables are instance variables of class DataTypeClass_Smith.

They hold the respective data(integer,float,string)for the class DataTypeClass_Smith.

Question 2 answer:

public DataTypeClass_Smith()

{

intVariable = 0; floatVariable = 0.0; stringVariable = “aString”;

}

DataTypeClass_Smith() is the default constructor of the class DataTypeClass_Smith and it initialise the instance variables with default values. When the object of type DataTypeClass_Smith is created with no parameters,then default constructor will be excuted and all the instance variables will be initialised with respective default values.

Question 3 answer:

public DataTypeClass_Smith( int intVar, float floatVar, String stringVar)

{

intVariable = intVar; floatVariable = floatVar; stringVariable = stringVar;

}

It is the parametrised constructor of the class DataTypeClass_Smith and it will initialise  all the instance variables with values present in the constructor.

Ex: DataTypeClass_Smith obj = new DataTypeClass_Smith(1,2.5,”John”);

parametrised constructor is called and values will be set to respective instance variables.

Question 4 answer:

It is a setter method for intVariable and it will set the value to the instance variable intVariable.

Ex: obj.setIntVariable(45);

Question 5 answer:

It is a getter method for floatVariable and it will return value of floatVariable when it is called.

Question 6 answer:

This is a toString() method for the class DataTypeClass_Smith.

It will print or return string format or readable format of the object which had all the instance variables with values


Related Solutions

Java Implement a class named “Fraction” with the following properties: numerator: int type, private denominator: int...
Java Implement a class named “Fraction” with the following properties: numerator: int type, private denominator: int type, private and the following methods: one default constructor which will create a fraction of 1/1. one constructor that takes two parameters which will set the values of numerator and denominator to the specified parameters. int getNum() : retrieves the value of numerator int getDenom(): retrieves the value of the denominator Fraction add(Fraction frac): adds with another Fraction number and returns the result in...
public class IntNode               {            private int data;            pri
public class IntNode               {            private int data;            private IntNode link;            public IntNode(int data, IntNode link){.. }            public int     getData( )          {.. }            public IntNode getLink( )           {.. }            public void    setData(int data)     {.. }            public void    setLink(IntNode link) {.. }         } All questions are based on the above class, and the following declaration.   // Declare an empty, singly linked list with a head and a tail reference. // you need to make sure that head always points to...
Question1: Define a class Human that contains: - The data fields "first name" and "last name"...
Question1: Define a class Human that contains: - The data fields "first name" and "last name" - A constructor that sets the first and last name to the instance variables. Create also a no-argument constructor - A getName() method which prints the first and last name Define the class Student which inherits Human and contains: - Private data field "mark" of type integer and a constructor which calls the superclass constructor Define the class Worker which inherits Human and contains:...
Consider the following java class: class Student {    private int student_Number;    private String student_Name;    public Student(int...
Consider the following java class: class Student {    private int student_Number;    private String student_Name;    public Student(int stNo,String name) {         student_Number=stNo;         student_Name=name;      }     public String getName() {       return student_Name;     }      public int getNumber() {       return student_Number;      }     public void setName(String st_name) {       student_Name = st_name;     } } Write a Tester class named StudentTester which contains the following instruction: Use the contractor to create a student object where student_Number =12567, student_Name = “Ali”. Use the setName method to change the name of...
public class Clock { private int hr; private int min; private int sec; public Clock() {...
public class Clock { private int hr; private int min; private int sec; public Clock() { setTime(0, 0, 0); } public Clock(int hours, int minutes, int seconds) { setTime(hours, minutes, seconds); } public void setTime(int hours, int minutes, int seconds) { if (0 <= hours && hours < 24) hr = hours; else hr = 0; if (0 <= minutes && minutes < 60) min = minutes; else min = 0; if(0 <= seconds && seconds < 60) sec =...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data field named id for the account. ■ A private float data field named balance for the account. ■ A private float data field named annualInterestRate that stores the current interest rate. ■ A constructor that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). ■ The accessor and mutator methods for id, balance, and...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double)...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double) Create getter/setter methods for all attributes Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the building object that is formatted nicely and contains all information (attributes) Create a FoodProduct Class that extends Product Add the following private attributes: expDate (java.util.Date) for expiration date refrigerationTemp (int) if 70...
Consider the following class: class Person {         String name;         int age;        ...
Consider the following class: class Person {         String name;         int age;         Person(String name, int age){                this.name = name;                this.age = age;         } } Write a java program with two classes “Teacher” and “Student” that inherit the above class “Person”. Each class has three components: extra variable, constructor, and a method to print the student or the teacher info. The output may look like the following (Hint: you may need to use “super”...
Given: class Monster {     private:     string name;     int dangerLevel;     public:     Monster(sting, int);     virtual void hunt()
Given: class Monster {     private:     string name;     int dangerLevel;     public:     Monster(sting, int);     virtual void hunt() = 0;     virtual void fight(Monster&);     string getName() const; }; class GiantMonster : public Monster {     protected:         int height;          public:         GiantMonster(string, int, int);         virtual void trample(); }; class Dinosaur : public GiantMonster {     public:     Dinosaur(string, int, int);     void hunt();     void roar(); }; class Kraken : protected GiantMonster {     public:     Kraken(string, int, int);     virtual void hunt();     void sinkShip(); }; Indicate if the code snippets below are...
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT