1Write a class called NumberOfGoals that represents the tota

1.Write a class called NumberOfGoals that represents the total number of goals scored by a football team. The NumberOfGoals class should contain a single integer as instance data, representing the number of goals scored. Write a constructor to initialize the number of goals to zero. Write a method called setGoal that increments the value by one whenever a goal is scored, and another method called getGoal that returns the total number of goals scored so far. Finally, create a driver class called GoalTracker that creates a few NumberOfGoals objects and tests their methods.

2. 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 that returns a one-line description of the shelf. Create a driver class called ShelfCheck, whose main method instantiates and updates several Shelf objects

Solution

1.

public class NumberOfGoals
{
  
public static void main(String[] args){
  
int counter = 0;
int goals[];
  
System.out.println(\"Goals\");
  
for(int i = 0; i <= 7; i++)
{
System.out.println(\"Goals: x+1\");
  
for(int j = 0; j <=2; j++)
{
goals[counter] = 5 + rand()% (10-5 +1);
System.out.println(goals[counter]);
  
}
  
}

2.

public class Shelf {
private double length;
private double breadth;
private int capacity ;
private boolean occupied ;
public Shelf(double length, double breath ,int capacity){
this.length = length;
this.breadth = breath;
this.capacity = capacity;
occupied = false;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getBreadth() {
return breadth;
}
public void setBreadth(double breadth) {
this.breadth = breadth;
}
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public boolean isOccupied() {
return occupied;
}
public void setOccupied(boolean occupied) {
this.occupied = occupied;
}
public String toString(){
return \"Length: \"+getLength()+\" Breadth: \"+getBreadth()+\" Capacity: \"+getCapacity()+\" Occupied: \"+isOccupied();
}
  
}

ShelfCheck.java

public class ShelfCheck {

  
public static void main(String[] args) {
Shelf s = new Shelf(10,20, 5);
System.out.println(s.toString());
s.setOccupied(true);
System.out.println(s.toString());
s.setBreadth(50);
s.setLength(30);
s.setCapacity(40);
s.setOccupied(true);
System.out.println(s.toString());

}

}

1.Write a class called NumberOfGoals that represents the total number of goals scored by a football team. The NumberOfGoals class should contain a single intege
1.Write a class called NumberOfGoals that represents the total number of goals scored by a football team. The NumberOfGoals class should contain a single intege

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site