Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working.
//Main File
import java.util.*;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
System.out.print("There are 5 humans.\n");
array();
}
public static String[] array()
{
//Let the user enter the names of the humans
String[] humans= new String[5];
Scanner input = new Scanner(System.in);
System.out.print("Enter the " + humans.length + "
names: ");
for (int i = 0; i < humans.length; i++)
{
humans[i] = input.nextLine();
}
for(int i=0;i<humans.length; i++)
{
System.out.print(humans[i]+" ");
}
return humans;
}
}
//Human file
import java.util.*;
import java.util.Scanner;
public class Human
{
Dog [] dogs;
public static void main(String[] args)
{
}
public Human()
{
int numDogs = Dog.random();
dogs = new Dog[numDogs];
for(int i=0; i<dogs.length; i++)
{
dogs[i] = new Dog();
}
for(int i=0;i<dogs.length; i++)
{
System.out.print(dogs[i]+" ");
}
}
}
//Dog file
import java.util.*;
import java.util.Scanner;
public class Dog
{
public static void main(String[] args)
{
}
public static int random()
{
int num = (int) (Math.random());
String[] dogs = new String[num];
return num;
}
public Dog()
{
}
}

import java.util.*;
public class Main {
public static void main(String[] args)
{
System.out.print("There
are 5 humans.\n");
// Let the user
enter the names of the humans
Human[] humans =
new Human[5];
Scanner input = new
Scanner(System.in);
System.out.print("Enter
the " + humans.length + " names: ");
for (int i = 0; i
< humans.length; i++) {
humans[i]
= new Human(input.nextLine());
}
for (int i = 0; i
< humans.length; i++) {
humans[i].print();
}
input.close();
}
}
class Human {
String name;
Dog[] dogs;
public Human(String name) {
this.name =
name;
int numDogs = (int)
(1 + 5 * Math.random());
dogs = new
Dog[numDogs];
for (int i = 0; i
< dogs.length; i++) {
dogs[i]
= new Dog();
}
}
public void print() {
System.out.println("Name:
" + name);
System.out.print("Dogs:
");
for (int i = 0; i
< dogs.length; i++) {
System.out.print(dogs[i].getName()
+ " ");
}
System.out.println();
}
}
class Dog {
String name;
Dog() {
String names[] =
{"Ace", "Apollo", "Bailey", "Bandit", "Baxter", "Bear", "Beau",
"Benji",
"Benny",
"Bentley", "Blue", "Bo", "Boomer", "Brady", "Brody", "Bruno",
"Brutus", "Bubba",
"Buddy",
"Buster", "Cash", "Champ", "Chance", "Charlie", "Chase", "Chester",
"Chico"};
name = names[(int)
(Math.random() * names.length)];
}
public String getName() {
return name;
}
}
**************************************************
Thanks for your question. We try our best to help you with detailed
answers, But in any case, if you need any modification or have a
query/issue with respect to above answer, Please ask that in the
comment section. We will surely try to address your query ASAP and
resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
Below I have my 3 files. I am trying to make a dog array that aggerates...
Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method getInput , which asks the user how many words there are, stores them in an array, and returns this array. printBackwards then takes this array of words, and prints it in reverse. Code Example: import java.util.Scanner; public class L17Num1{ public static void main(String[] args) { String[] sArray=getInput(); printBackwards(sArray); } public static String[] getInput() { System.out.println("How many...
How can I make this program sort strings that are in a text file and not have the user type them in? I need this done by 5:00 AM EST tommorow please. import java.util.*; public class MergeDemo { public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.print("How many lines to be sorted:"); int size=input.nextInt(); String[] lines=new String[size]; lines[0]=input.nextLine(); System.out.println("please enter lines..."); for(int i=0;i { lines[i]=input.nextLine(); } System.out.println(); System.out.println("Lines Before Sorting:"); System.out.println(Arrays.toString(lines)); mergeSort(lines); System.out.println(); System.out.println("Lines after Sorting:"); System.out.println(Arrays.toString(lines)); } public...
I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...
Write a Java method that should take an ArrayList as a parameter, print its element in the reverse order. The main function that calls the method is the following: import java.util.*; public class ReverseGen { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("How many numbers do you want to input?"); int num = input.nextInt(); ArrayList<Double> d = new ArrayList<Double>(num); for(int i = 0 ; i < num; i++){ System.out.print("Enter...
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...
JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in); System.out.println("Seed:"); int seed = scanner.nextInt(); System.out.println("Length"); int length = scanner.nextInt(); Random random...
Computer Science - Java
Explain the code step by step (in detailed order). Also explain
what the program required. Thanks
7 import java.io.File; 8 import java.util.Scanner; 9 import java.util.Arrays; 10 import java.io.FileNotFoundException; 12 public class insertionSort 13 14 public static void insertionSort (double array]) 15 int n -array.length; for (int j-1; j < n; j++) 17 18 19 20 21 double key - array[j]; int i-_1 while ( (i > -1) && ( array [i] > key array [i+1] -...
Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q { public static LinkedList<String> dogs = new LinkedList<String> (); public static LinkedList<String> cats = new LinkedList<String> (); public static LinkedList<String> animals = new LinkedList<String> (); public static void enqueueCats(){ System.out.println("Enter name"); Scanner sc=new Scanner(System.in); String name = sc.next(); cats.addLast(name); animals.addLast(name); } ...
I need a java flowchart for the following code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter the input size: "); int n=sc.nextInt(); int arr[]=new int[n]; System.out.print("Enter the sequence: "); for(int i=0;i<n;i++) arr[i]=sc.nextInt(); if(isConsecutiveFour(arr)) { System.out.print("yes the array contain consecutive number:"); for(int i=0;i<n;i++) System.out.print(arr[i]+" "); ...
In the code shown above are
two parts of two different exercises. HOW WE CAN HAVE BOTH OF THEM
ON THE SAME CLASS BUT SO WE CAN RECALL them threw different
methods. Thank you.
1-First exercise
import java.util.Scanner;
public class first {
public static int average(int[] array){
int total = 0;
for(int x: array)
total += x;
return total / array.length;
}
public static double average(double[] array){
double total = 0;
for(double x: array)
total += x;
return total /...