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...
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...
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...
public class Date { private int dMonth; //variable to store the month private int dDay; //variable...
public class Date { private int dMonth; //variable to store the month private int dDay; //variable to store the day private int dYear; //variable to store the year //Default constructor //Data members dMonth, dDay, and dYear are set to //the default values //Postcondition: dMonth = 1; dDay = 1; dYear = 1900; public Date() { dMonth = 1; dDay = 1; dYear = 1900; } //Constructor to set the date //Data members dMonth, dDay, and dYear are set //according to...
Design a class named Account that contains: A private int data field named id for the...
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 private double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. The accessor and mutator methods for id, balance, and annualInterestRate. A method named getMonthlyInterestRate() that returns the monthly interest rate. A method named withdraw(amount)...
Design a class named BankAccount that contains: A private int data field named id for the...
Design a class named BankAccount that contains: A private int data field named id for the account. A private double data field named balance for the account. A constructor that creates an account with the specified id and initial balance. A getBalance() method that shows the balance. A method named withdraw that withdraws a specified amount from the account. Create a subclass of the BankAccount class named ChequingAccount. An overdraftlimit to be 1000 for ChequingAccount . Test your ChequingAccount class...
JAVA -The next three questions use the following class: class Identification { private int idNum;   ...
JAVA -The next three questions use the following class: class Identification { private int idNum;    public Identification() { this(0); }    public Identification(int startingIdNum) { idNum = startingIdNum; }    public int getIdNum() { return idNum; }    public void setIdNum(int idNum) { this.idNum = idNum; } } Here is one program using the above class: public class Main {    public static void main(String[] args) {        Identification i1 = new Identification();        Identification i2 =...
public class SumMinMaxArgs { private int[] array; // You will need to write the following: //...
public class SumMinMaxArgs { private int[] array; // You will need to write the following: // // 1. A constructor that takes a reference to an array, // and initializes an instance variable with this // array reference // // 2. An instance method named sum, which will calculate // the sum of the elements in the array. If the array // is empty (contains no elements), then this will // will return 0. You will need a loop for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT