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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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