


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
this document based on assignment and quizes related to object oriented programming and its help student in their study
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



for accessor methods and mutator methods?
Assignment 2 Semester: VI Batch: 2018 Due Date: 22-July-2019 Max Marks: 10 Instructions: Attempt all questions
String s1 = "Welcome to Java"; String s2 = s1; String s3 = new String("Welcome to Java"); String s4 = "Welcome to Java";
What are the results of the following expressions?
1. The atoms of different elements have different numbers of protons, neutrons and electrons. Electrons are negatively charged, protons are positively charged, and neutrons have no charge. a) In an object oriented programming language, write a definition for an Atom class that contains: fields for storing the numbers of protons, neutrons and electrons with appropriate visibility; setter and getter methods for manipulating these fields, ensuring that the minimum value for electrons and protons is 1, and the minimum value for neutrons is 0; a constructor that initializes new objects of atom to be the smallest element (Hydrogen), for which the number of protons is 1, the number of neutrons is 0, and the number of electrons is 1. b) Write a new method for the atom class called isIon that will return true or false, depending upon whether the atom is an ion. An atom is an ion if it is charged (i.e., if the number of electrons ≠ the number of protons). c) Write a new method for the atom class called getAtomicMassNumber that will calculate and return the atomic mass number of the atom. Atomic mass number of an atom (often denoted A) is defined as the number of protons plus the number of neutrons. [3 Marks] 2. Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 cent toll. Mostly they do, but sometimes a car goes by without paying. The tollbooth keeps track of the number of cars that have gone by, and of the total amount of money collected. . Model this tollbooth with a class called TollBooth. a. s1 == s b. s1 == s c. s1 == s d. s1.equals(s3) e. s1.equals(s4) f. "Welcome to Java".replace("Java", "HTML") g. s1.replace('o', 'T') h. s1.replaceAll("o", "T") i. s1.replaceFirst("o", "T") j. s1.toCharArray()
volume. The volume attribute will hold a number value representing the loudness (0 being no sound). The television object will also be able to control the state of its attributes. These controls become methods in our class. setChannel. The setChannel method will store the desired station in the channel field. power. The power method will toggle the power between on and off, changing the value stored in the powerOn field from true to false or from false to true. getChannel. The getChannel method will return the value stored in the channel field. getVolume. The getVolume method will return the value stored in the volume field. getBrand. method will return the constant value stored in the Brand field. getScreenSize. The getScreenSize method will return the constant value stored in the screensize field. Create a constructor definition that has two parameters, brand and a screen size. These parameters will bring in information You can only execute (run) a program that has a main method, so write a driver program. Declare Television object called portable. Instantiate portable to be a Sharp 19 inch television. Use a call to the power method to turn the power on. Use the suitable method to change the channel to 56. Print out the values of brand , screensize and channel as output to your application [2 Marks]