359,068 views
2 votes
2 votes
Write a program that asks the user for the name of their dog, and then generates a fake DNA background report on the pet dog. It should assign a random percentage to 5 dog breeds (that should add up to 100%!)

User Ikechukwu Eze
by
2.8k points

1 Answer

25 votes
25 votes

Answer:

Code:

import java.util.*;

public class Main{

public static void main(String []args){

Scanner sc = new Scanner(System.in);

System.out.println("What is your dog's name?");

// Entering name of dog

String name = sc.nextLine();

System.out.println("Well then, I have this highly reliable report on " + name + "'s prestigious background right here.");

System.out.println("\\\\Sir " + name + " is\\\\");

//Generating random numbers

Random ran = new Random();

int sum = 0;

int a = 0;

int b = 0;

int c = 0;

int d = 0;

int e = 0;

while(sum != 100)

{

a = ran.nextInt(100);

b = ran.nextInt(100-a);

c = ran.nextInt(100-b);

d = ran.nextInt(100-c);

e = ran.nextInt(100-d);

sum = a + b+ c + d + e;

}

System.out.println(a + "% St. Bernard");

System.out.println(b + "% Chihuahua");

System.out.println(c + "% Dramatic RedNosed Asian Pug");

System.out.println(d + "% Common Cur");

System.out.println(e + "% King Doberman");

System.out.println("\\\\Wow, that's QUITE the dog!");

}

}

User Dondublon
by
2.5k points