1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Allushta [10]
3 years ago
13

Create a public class Dog that stores a single double age set by the constructor. (Reject negative ages using assert.) Dog shoul

d also provide a single class method named isOlder. isOrder should accept two Dog instances and return true if the first is older than the second, and false otherwise. You should also assert that both passed instances are not null.
Computers and Technology
1 answer:
hjlf3 years ago
7 0

Answer:

Explanation:

The following is written in Java and has the methods as requested in the question...

class Dog {

   private double age;

   public Dog(double v) {

       assert v >= 0:" Not valid";

       this.age = v;

   }

   public boolean isOlder(Dog dog1, Dog dog2) {

       if (dog1.age > dog2.age) {

           return true;

       } else {

           return false;

       }

   }

}

You might be interested in
Tortise and hare race java g Modify the main class so it runs the race 100 times and reports how many times each runner wins. (T
SOVA2 [1]

Answer:

Game.java file

import java.util.Scanner;

public class Game {

/**

* t_pos and h_pos are the current positions of the Tortoise and Hare

*/

static int t_pos,h_pos;

static Tortoise tortoise;

static Hare hare;

public static void main(String[] args) {

play(); /*starting the game*/

}

public static void play(){

/**

* the method will starts the play, loop until the game is over, displays the winner

* and prompts the user if they want to play again

*/

/**

* defining Tortoise and Hare objects

*/

tortoise=new Tortoise();

hare=new Hare();

t_pos=1;

h_pos=1;

System.out.println("The race is about to start");

tortoise.printTrack();

hare.printTrack();

while(t_pos != 50 && h_pos !=50){

System.out.println("\n\n\n"); /*printing blank lines*/

t_pos=tortoise.move(); /*moving and getting the current position of tortoise*/

h_pos=hare.move();/*moving and getting the current position of hare*/

tortoise.printTrack(); /*displaying the tracks*/

hare.printTrack();

try { /*comment this part to skip the 1s break between each round; for testing*/

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

System.out.println("\nRace Over");

if(t_pos==50 && h_pos==50){

System.out.println("Its a tie");

}

else if(t_pos==50){

System.out.println("Tortoise wins");

}else if(h_pos==50){

System.out.println("Hare wins");

}

System.out.println("Do you want to play again? (y/n)");

Scanner scanner=new Scanner(System.in);

String ch=scanner.next();

if(ch.equalsIgnoreCase("y")){

play();

}else if(ch.equalsIgnoreCase("n")){

System.out.println("Thanks for playing, Goodbye");

}else{

System.out.println("Invalid choice, quitting..");

}

}

}

//Tortoise.java

public class Tortoise {

/**

* the current position of the tortoise

*/

int position;

/**

* track array

*/

char[] track;

/**

* speed of tortoise

*/

int speed=1;

public Tortoise() {

position=0;

track=new char[50];

for(int i=0;i<track.length;i++){

/**

* filling the track

*/

track[i]='-';

}

}

public int move(){

if(position<track.length){

position=position+speed;

}

return position+1;

}

public void printTrack(){

/**

* the current position of tortoise will be displayed by 'T' everything else will be '-'

*/

System.out.println();

for(int i=0;i<track.length;i++){

if(i==position){

System.out.print('T');

}else{

System.out.print(track[i]);

}

}

}

}

//Hare.java

import java.util.Random;

public class Hare {

int position;

int speed=10;

char[] track;

/**

* Random object to generate a random number

*/

Random random;

/**

* resting percent denotes how much time Hare will be resting

*/

int resting_percent=90;

public Hare() {

position=0;

track=new char[50];

for(int i=0;i<track.length;i++){

track[i]='-';

}

random=new Random();

}

public int move(){

int n=random.nextInt(100-1)+1; /*generating a random number between 1 and 100*/

if(n<=resting_percent){

/**

* at rest; will not move, returns the current position.

*/

return position;

}else{

/**

* not resting..

*/

if(position<track.length){

if(position+speed>=track.length){

position=track.length-1;

}else{

position=position+speed;

}

}

return position+1;

}

}

public void printTrack(){

System.out.println();

for(int i=0;i<track.length;i++){

if(i==position){

System.out.print('H');

}else{

System.out.print(track[i]);

}

}

}

}

/*Output (partial and random)*/

The race is about to start

T-------------------------------------------------

H-------------------------------------------------

-T------------------------------------------------

H-------------------------------------------------

--T-----------------------------------------------

H-------------------------------------------------

---T----------------------------------------------

----------H---------------------------------------

.

.

.

.

-----------------------------------------------T--

-------------------------------------------------H

Race Over

Hare wins

Do you want to play again? (y/n)

y

The race is about to start

T-------------------------------------------------

H-------------------------------------------------

-T------------------------------------------------

H-------------------------------------------------

.

.

.

.

-----------------------------------------------T--

--------------------H-----------------------------

------------------------------------------------T-

--------------------H-----------------------------

-------------------------------------------------T

--------------------H-----------------------------

Race Over

Tortoise wins

Do you want to play again? (y/n)

n

Explanation:

3 0
3 years ago
The ________ model allows the owner of a resource to manage who can or cannot access the item. Owners maintain this access throu
blagie [28]

Answer:

Discretionary Access Control model

Explanation:

Discretionary Access Control (DAC) gives owners of a resource full control of objects/items they have created or been given access to, this also includes sharing the objects/items with other subjects. These owners have control over their data and maintain access through ACLs. The access-control list (ACL), is a list of permissions attached to an object in a computer file system.

The Owners can decide to grant other users access to their files, change their attributes, alter them, or delete them. DACs are discretionary because the owner can transfer information access to other users.

5 0
3 years ago
Hello everyone. New ppl on Ro.blox? I want to play sometime.
alexira [117]

Answer:

Hello :)

Explanation:

Yesh i play Ro.blox, maybe u or me could friend each other

6 0
2 years ago
Read 2 more answers
How many answers do you need to be able to write messages on here??
Kipish [7]

1,000

Hope this helps!



~Courtney

3 0
2 years ago
Carlie was asked to review a software project for her company to determine specific deadlines. Which part of project management
Elis [28]

Answer:

Resources

Explanation:

Carlie certainly requires to review the resources. It is important to find out how many software engineers, testers, etc. are available. And only then Carlie can find out the exact deadlines as required here. And hence, she must have look at the resources while determining the specific deadlines. Hence, resources are the correct option.

3 0
3 years ago
Read 2 more answers
Other questions:
  • If reading or writing a cache line of size 64 bytes to Flash requires 2.56 μJ and DRAM requires 0.5 nJ, and if idle power consum
    9·1 answer
  • Match each item with a statement below. a device used in mobile devices to sense the physical position of the device an area whe
    11·1 answer
  • SQL a. has become the de facto standard database language b. can be used to define database systems c. both a. and b. d. none of
    10·1 answer
  • 1. Define a C++ function with the name evaluateBook. The function receives as one argument the name of the file to be processed
    13·1 answer
  • Which are factors that go into a project plan?
    8·1 answer
  • 1 Point
    14·1 answer
  • Explain why it is not necessary for a program to Explain why it is not necessary for a program to be completely free of defects
    13·1 answer
  • Blending two or more colours is called​
    6·1 answer
  • Does anyone know what i did wrong?
    13·1 answer
  • Software is in -----language​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!