Preview

Program to Explain Getter and Setter Functions

Good Essays
Open Document
Open Document
436 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Program to Explain Getter and Setter Functions
1369-6-15E AID:000 | 27/012013
-------------------------------------------------

Program Plan: * Create a class Pizza * Define the variables * Provide methods to get and set these variables
-------------------------------------------------

/*********************************************************************** The program Pizza.java creates a class Pizza and defines methods to get and set variables in the class
***********************************************************************/
Program:
//creating class Pizza class Pizza
{
//declaring the fields in the class String Toppings; int Diameter; double Price;
-------------------------------------------------

//defining methods to set and get the field Toppings respectively void setToppings(String z) { //setting the filed Toppings Toppings=z; }

String getToppings() { return Toppings; }
-------------------------------------------------

//defining methods to set and get the field Diameter respectively void setDiameter(int x) { //setting the filed Diameter Diameter=x; }

int getDiameter() { return Diameter; }
-------------------------------------------------

//defining methods to set and get the field Price respectively void setPrice(double y) { //setting the field Price Price=y; }

double getPrice() { return Price; }
}
-------------------------------------------------

Program Plan: * Create a class Pizza * Define the variables * Provide methods to get and set these variables * Create another class TestPizza * Initialize an instance of the class Pizza * Set the fields of the instance with a value * Output those fields with the use of getter functions

You May Also Find These Documents Helpful

  • Powerful Essays

    The purpose of this Lab. is to familiarize student how to solve practical problems programmatically; they will practice on elementary programming using primitive data types, variables, constants, operators, expressions, and input and output. Also, they will learn how to diagnose errors that may occur when a program is compiled or executed. There are some exercises, through which they will understand the concept learn in this chapter.…

    • 2338 Words
    • 10 Pages
    Powerful Essays
  • Satisfactory Essays

    Nt1310 Unit 4 Lab

    • 252 Words
    • 2 Pages

    ➢ To define a class of your own and use it to create an object.…

    • 252 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Copyright © 2011 by Maria Litvin and Gary Litvin All rights reserved. Teachers who purchased Java Methods are allowed to make one copy. However, we ask you not to do this to help keep answers and solutions confidential. No part of this material may be reproduced for any other purpose without a prior written permission of the authors.…

    • 3908 Words
    • 16 Pages
    Powerful Essays
  • Satisfactory Essays

    understanding macros

    • 668 Words
    • 6 Pages

    Complete the following tasks by using the Microsoft® Word® document located on the student website:…

    • 668 Words
    • 6 Pages
    Satisfactory Essays
  • Good Essays

    Week 1 Homework

    • 843 Words
    • 5 Pages

    2. Find area of first pizza = pi * (diameter of first size pizza / 2) 2…

    • 843 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    using not only for this class but other classes as well. In the last presentation there were…

    • 466 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Reveiwing the Basics

    • 626 Words
    • 3 Pages

    Which is the least expensive edition of Vista that can use the Aero user interface?…

    • 626 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Every kind of pizza begins with the crust, but before you have crust you have pizza dough. The soft off-white pizza dough is very malleable. The dough feels cool in your hands as you shape it into a circle adding flour as you knead the dough, and of course there’s the tossing of the dough in the air and catching it which in my opinion is the fun part. After you have your pizza dough shaped and ready, you spread the ingredient that really sets off the pizza, tomato sauce. The aroma of tomatoes and spices blended together perfectly smell wonderfully, and the zesty and robust taste is even better when you have the perfect sauce. After you apply the sauce, you add a layer of cheese. Mozzarella is the usual choice for cheese as it complements the pizza rather well. Especially when my favorite pizza toppings are added which are pepperoni, sausage, and Canadian bacon. Together, the ingredients create an amazing pizza. The last step in creating a pizza is baking the pizza. Hearing the tempting sound of the cheese sizzling as it melts atop the sauce covered golden brown crust in the oven almost makes you want to take the pizza out early and devour it.…

    • 343 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Make a 4-5 star pizza in less than 30 seconds and have the pizza out of the oven in less than 8 minutes.…

    • 956 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Assignment #1 – Chapter #1 M/C Questions # 1 – 25, pp. 22-25 (2 pts. each; 50 points total) 1. B 2.…

    • 810 Words
    • 8 Pages
    Satisfactory Essays
  • Good Essays

    C+++ Basic Lessons

    • 711 Words
    • 3 Pages

    The C++ compiler also determines the data type of variable to be output and selects the appropriate stream insertion operator to display the value. The << operator is overloaded to output data items of built-in types integer, float, double, strings and pointer values.…

    • 711 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Fundamentals

    • 315 Words
    • 2 Pages

    |Main message/topic (maybe insert |Coercive Persuasion is beginning of all learning, organizational learning exists if: (see next) |…

    • 315 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Java Calculator CMD

    • 889 Words
    • 4 Pages

    import java.util. *; class pup { public static void main (String [] args) { int a,b,op; int c = 0; Scanner fSC = new Scanner(System.in); System.out.println("Welcome to CMD basic calculator!\n"+"Press ENTER key to continue . . ."); Scanner aKey = new Scanner(System.in); String akeyp = aKey.nextLine(); System.out.println("Enter first number:"); a = fSC.nextInt(); System.out.println("Input operator to be used( Ex. 1):\n"+"1. Addition\n"+"2. Subtraction\n"+"3. Multiplication\n"+"4.…

    • 889 Words
    • 4 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Data Dictionary

    • 457 Words
    • 2 Pages

    Well, one basic usage that came into my mind while writing this, this can help us design a class and to break down programming problems (read my previous blog for more information). This can help you define and design the classes needed to solve a certain problem. As an example (related to my previous blog) we can define that Account or User class will have for example a string representing the name, another string is representing the number, an integer being the PIN number. As you can…

    • 457 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Class diagram

    • 649 Words
    • 3 Pages

    There are two scopes for members: classifiers and instances. Classifiers are static members while instances are the specific instances of the class. If you are familiar with basic OO theory, this isn't anything groundbreaking.…

    • 649 Words
    • 3 Pages
    Good Essays

Related Topics