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

  Assume an ideal gas mixture is in contact with water

Assume an ideal gas mixture is in contact with water. Determine the equilibrium concentration of the contaminant in the liquid is the gas stream is composed of 200 ppm of benzene in air

  Design a java application to read a file containing data

Design a Java application that will read a file containing data related to the passengers on the Titanic. The description of the file is shown below. The application should provide statistical results on the passengers including

  Write a program that plots a bar chart for comparing mtbfs

Write a program that plots a bar chart for comparing the MTBFs of different elevator models. The data to be displayed is prepared in a file: Each line consists of the model's letter and the MTBF that has been measured for that file.

  Program that allows the user to enter an unknown number

Writer a program that allows the user to enter an unknown number of characters, stores those characters in a data structure (a vector) and then prints the values to the screen.

  Write a comparator class that compares products by price

Write a comparator class that compares Products by price. Declare a priority queue that uses the comparator class in number 3 to compare Products.

  Implement a client program

Implement a client program with a main method to demonstrate the evolution of the sales tax rates in the 50 US states over the last 10 years. Declare a two-dimensional array of values representing the sales tax rates. Dimension 1 represents the st..

  What is an abstract class and how does it differ from the

question 1 what is an abstract class and how does it differ from a regular class? question 2 why are abstract class

  Demonstrate instances of each class and tests

Demonstrate instances of each class and tests of all control paths in a program.

  Implement a simple number guessing game using html forms

Your assignment is to implement a simple number guessing game using HTML forms and a Java servlet. The HTML page should introduce the game and provide a form for the user to guess a number on. The servlet should use an HTTP session object to store..

  Write down a java program that implements a stack of

write a java program which implements a stack of integers. an integer should only be pushed into the stack if it is

  Programming using the java language

Programming using the Java language. The basic concepts of object-oriented programming. Topics used will include algorithmic logic, control structures, data and program design, objects and classes.

  Marketing necessary for practice-hospital to successful

Why is marketing necessary for a practice or hospital to be successful? What considerations should be taken into account when marketing health care services or products? (Hint think about all the medication ads you seen on tv or in magazines)

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