Define variables constructors and methods

Assignment Help JAVA Programming
Reference no: EM131081884

Programming in Java

Java and OOPs

Classes are the building blocks of object-oriented programming. Understanding the parts of a class is critical to coding in Java. Classes utilize data passed to it. In this lesson, two classes are created. One class calls the other and uses its methods to process the data.

Assignment:

To use a class, call the constructor. Below are two Java classes. The name of the first is FirstClassOOPS. It defines variables, constructors, and methods. The second class is ClassClient. In ClassClient, the constructor for FirstClassOOPS is called. The constructor initializes the variable name to "John Smith" and age to 62. Then a method in FirstClassOOPS is used to print out the results below.

My name is John Smith.
My age is 62.

Part I:

Modify the code to make sure the print out is as follows.

My name is John Smith.
My age is 62.

Make a screenshot of the output and include it as an attachment to the Assignment. Also, include the program code in a text file to be evaluated. Make sure you code is commented to receive full credit.

Part II:

Identify the following in the FirstClassOOPS class.

• Constructor(s)
• Mutator Methods (Set methods)
• Acessor Methods (Get methods)
• Name of methods that returns values
• Name the methods that do not return any values
• List the methods that have parameters.

FirstClassOOPS

public class FirstClassOOPS {

// Declare Variables

private String sName;

privateint sage;

//Create default constructor

publicFirstClassOOPS()

{

sName="None";

sage = 18;

}

//Create a constructor

publicFirstClassOOPS(String name, int age)

{

//initialize variables

sName = name;

sage = age;

}

//Mutator Method = Method that changes the name

public void setName(String name)

{

sName = name;

}

// Mutator Method = Method that changes the age

public void setAge(int age)

{

sage = age;

}

//Getter Method = Method that returns the value of Name

public String getName()

{

returnsName;

}

//Getter Method = Method that returns the value of age

publicintgetAge()

{

return sage;

}

//To String Method = returns the name and age

public String toString()

{

String message = "My name is "+sName+".\nMy age is "+sage+".";

return message;

}

}

ClassClient below.

public class ClassClient {

public static void main(String[] args)

{

//Create a FirstClassOOPS variable with name = John Smith and age = 62

FirstClassOOPS g = new FirstClassOOPS();

String outPutString = g.toString();

System.out.println(outPutString);

// The output should be

// My name is John Smith.

// My age is 62.

//

}

}

Submit your screenshots, answers and code in a file with your GID number.

Reference no: EM131081884

Questions Cloud

What is the probability q that a random ticket will be a win : What is the probability q that a random ticket will be a winner?
What kind of conversion procedures were being used : Discuss a recent experience with an information system that was undergoing a change or upgrade. What kind of conversion procedures were being used? How did this affect your interaction with the system as a user? Were others affected, as well?
Techniques for reading or writing files in php : 1. Describe two techniques for reading or writing files in PHP. 2. Why we need to always sanitize user inputs before using them in your queries?
Should you build your circuit with ordinary devices : Should you build your circuit with ordinary devices or ultrareliable devices in order to maximize your expected profit E[R]? Keep in mind that your answer will depend on k.
Define variables constructors and methods : It defines variables, constructors, and methods. The second class is ClassClient. In ClassClient, the constructor for FirstClassOOPS is called.
Best practices for security in rdbms : "Can you do some research and tell us a little on best practices for security in RDBMS' in regard to transactions? What if a hacker takes money in a transaction sent to their account and then issue a ROLLBACK to the calling bank?"
What is the expected monthly cost e[c] : For the cellular phone in Problem 2.6.6, express the monthly cost C as a function of M, the number of minutes used. What is the expected monthly cost E[C]?
Create your rbf model : Use rbf function in R to create your RBF model. Try cluster numbers 5 to 25. Use your hold-out validation set to figure out the best number of clusters. Report the best number of clusters and the corresponding validation accuracy rate
What is the pmf of c the cost of buying the stock : What is the PMF of C,

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java application using netbeans ide

Write a Java application using NetBeans Integrated Development Environment (IDE) or jGROUP IDE that calculates the total annual compensation of a salesperson

  Mean and standard deviation write a program that reads a

mean and standard deviation. write a program that reads a set of floating-point data values from the input. when the

  Create java application-input miles driven and gallons used

Create Java application which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and display miles per gallon obtained for each tankful.

  Implement a sorting algorithm for inclusion in a package

Prepare a targeted plan in which you present your detailed strategies to recruit and select 20 Engineers to hire (full-time or part-time) within 8 months - Implement a sorting algorithm for inclusion in a package for a lucrative client.

  Number of elements in the array dynamically

When instantiating an array, you can assign the number of elements in the array dynamically, using a variable (as opposed to using a constant). What situation will that be useful? and why?

  Write a java program called namecollector

Write a Java program called "NameCollector" that contains an object invocation for a class called "Collector".

  Calculates the total annual compensation of a salesperson

Write a Java application using an Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson

  What is meant by the name dynamic array

So how would you dimension this array if you don't know how many elements you will need? Sure, you could dimension the array to be very large arrStudents[1000], but that would be a big waste, especially if you ended up only needing 5 elements, so ..

  Write a java binary search tree program

write a JAVA binary search tree program

  Create file using any word-processing program or text editor

Create a file using any word-processing program or text editor. Write an application that displays the file's name, containing folder, size, and time of last modification. Save the file as FileStatistics.java.

  How to compile and debug your work

You will be writing a Java program to allow people to play the 24-puzzle (the obvious variant where the frame is 5x5) puzzle) in a text based context. My goal is that you recall how to enter programs (probably using jGrasp), how to write a small/s..

  Write a code bmitable java that produces a table of bmi

The goal of this lab is to write a code BMITable.java that produces a table of BMI (the Body-Mass Index). The body-mass index of a person is determined by the height and weight of the person, given by the formula.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd