Question

8). Name five of the fundamental ter ns which encompass object-oriented programming 9). Write a class called NumberOfGoals that represents the total number of goals scored by a ootball team. The NumberOfGioals class should contain a single integer as data, representing the number of goals scored. Write a constructor to initialize the number of goals to Zero. 10). Write a set of instructions to prompt the user for an int value and input it using the Scanner class into the variable x and prompt the user for a float value and input it using the Scanner class into the variable y 11). Write a class called Shelf that contains instance data that represents the length, breadth, and capacity of the shelf. Also include Boolean variable called occupied as data that represents whether the shelf is occupied or not. Define the Shelf constructor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant ( the constructor should initialize occupied to false. 12) Provide three examples of code using assignment statements where one assignment statement would result in a syntax error, one would result in a logical error, and one would result in a run-time error

0 0
Add a comment Improve this question Transcribed image text
Answer #1

8. Five fundamental terms associated with object-oriented programming are -

a)inheritance - getting the property of a parent class in a base class

b)polymorphism - to exist in more than one form

c)encapsulation - wrapping of text and data into a single unit

d)abstraction - to show only the least amount of data that is required by the user

e)classes - an collection of objects

9.

The code for the following question is as follows:

pulbic class NumberOfGoals

{

int goals;

public NumberOfGoals()

{

goals=0;

}

public static void main(String args[])

{

//rest of the code in here

}

}

In here NumberOfGoals in the class name followed by the integer goals.When we call the constructor NumberOfGoals() it is automatically initialized to 0;

10.The code for the following question in Java is as follows

import java.util.*;

public class input

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int x = sc.nextInt();

float y= sc.nextFloat();

}

}

Here we import the scanner class by callin import over java.util,and use an object of the Scanner class namely sc to call the nextInt and nextFloat functions for keyboard input and storing the data in x and y respectively.

11.The code for the following question is as follows

import java.util.*;

public class Shelf

{

int length;

int bredth;

boolean capacity;

public Shelf(int length,int bredth)

{

this.length=length;

this.bredth=bredth;

capacity=false;

}

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

Shelf ob=new Shelf(sc.nextInt(),sc.nextInt());

}

}

Here we are having 3 global variables namely length,bredth and capacity.However Since we need to use a constructor to initialize their values,we use the this keyword to initialize the global values of the variables with the local parametric value.However to call a constructor an object needs to be created,as such we create an object of of type Shelf,and the values in it are passed from the Scanner object's call to nextInt().

12. Example of an syntax error is as follows :

class example

{

pub static void main(String args[])

{

}

}

Here we have written 'pub' instead of public as a result error is throws.

Example of logical error is as follows :

public class Example
{
public static void main(String[] args)
{
int k;
for (k=1; k<=10; k++) ;
{
System.out.println("Count is " + k);
}
}
}

Here a semicolon is present after the for loop as such it shows itself as an empty loop and its body is treated as a seperate block of code

Example of runtime error is :

public class Example
{
public static void main(String[] args)
{
int x=0;
int y=100;
int div=y/x;
}
}

Since we are dividing 100 by 0 an divide by zero exception is thrown at runtime.

Add a comment
Know the answer?
Add Answer to:
8). Name five of the fundamental ter ns which encompass object-oriented programming 9). Write a class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class called Shelf that contains instance data that represents the length, breadth, and capacity...

    Write a class called Shelf that contains instance data that represents the length, breadth, and capacity of the shelf. Also include a boolean variable called occupied as instance data that represents whether the shelf is occupied or not. Define the Shelf constructor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant (the constructor should initialize occupied to false). Include getter and setter methods for all instance data. Include a toString method...

  • ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class...

    ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...

  • C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class...

    C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class called Player that represents a player in the National Hockey League. Player class Use the following class definition: class Player { public: Player(); Player( const char [], int, int, int ); void printPlayer(); void setName( const char [] ); void setNumber( int ); void changeGoals( int ); void changeAssists( int ); int getNumber(); int getGoals(); int getAssists(); private: char name[50]; int number; int goals;...

  • Programming assignment for Java: Do not add any other instance variables to any class, but you...

    Programming assignment for Java: Do not add any other instance variables to any class, but you can create local variables in a method to accomplish tasks. Do not create any methods other than the ones listed below. Step 1 Develop the following class: Class Name: College Degree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String Name: courseCreditArray Access modifier:...

  • Use your Car class from the previous Programming Assignment. For this assignment, create a new class...

    Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • Step 1 Develop the following class: Class Name: Bag Access Modifier: public Instance variables Name: name...

    Step 1 Develop the following class: Class Name: Bag Access Modifier: public Instance variables Name: name Access modifier: private Data Type: String Name: currentWeight Access modifier: private Data Type: double Name: maximumWeight Access modifier: private Data Type: double Constructors Name: Bag Access modifier: public Parameters: none (default constructor) Task: sets the value of the instance variable name to the empty string sets the value of the instance variable currentWeight to 0.0 sets the value of the instance variable maximumWeight to...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

  • specs for ComputeAverage ComputeAverage Write a class called ComputeAverage what it does: asks the user to...

    specs for ComputeAverage ComputeAverage Write a class called ComputeAverage what it does: asks the user to enter three double numbers (see examples below), it uses Scanner class to read from standard input each one of the doubles entered by the user. it then prints the average of the three numbers. Suggested steps: 1. prompt the user to enter each of the three doubles by printing. 2. read each of the three doubles using a Scanner. Remember you need to declare...

  • CS102 : JAVA Object-Oriented Programming. 1 Write a class Card whose instances represent a single playing...

    CS102 : JAVA Object-Oriented Programming. 1 Write a class Card whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties an integer for the rank (1 (corresponding to Ace) ,2,3, 13 (correspond ing to King) and suit (Spades, Hearts, Diamonds, or Clubs). Make the suit an enumerated data type. Include getters and setters and a method that tests if a card is valid. Write a class named Deck whose instances are full...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT