Questions
Java - Text File to Arrays and output ------------------------------------------------------------------------------ I need to have a java program...

Java - Text File to Arrays and output

------------------------------------------------------------------------------

I need to have a java program read an "input.txt" file (like below) and store the information in an respective arrays. This input.txt file will look like below and will be stored in the same directory as the java file. The top line of the text represents the number of people in the group for example. the lines below it each represent the respective persons preferences in regards to the other people in the group. I would then like the java program to output as a string each array and its elements.

Example of "input.txt" that would be read

4

2 3 4

1 3 4

1 2 4

1 2 3

As you can see the top line says there are 4 people in this group and person #1 which is line #2 prefers to be in a group with persons 2, 3, and 4 respectively. So for Person #1 it would be an Array with 3 elements being 2, 3, and 4 in that order.

The java program in this case would read the .txt file. create 4 arrays based on line #1 saying there are 4 people and then it would output as a string the 4 arrays and their respective elements in order,

Example Output:

Person #1 prefers 2, then 3, then 4

Person #2 prefers 1, then 3, then 4

.

.

.

The java program should be able to work with text files that have different numbers of people, it should create # of arrays based on the number on line 1.

In: Computer Science

complete java binary search tree /* * Complete the printInLevelOrder() method * Complete the visuallyIdentical(A4BST rhs)...

complete java binary search tree

/*
* Complete the printInLevelOrder() method
* Complete the visuallyIdentical(A4BST rhs) method
* No other methods/variables should be added/modified
*/
public class A4BST<E extends Comparable<? super E>> {
   /*
   * Grading:
   * Correctly prints values in level order - 1.5pt
   * Runs in O(N) - 1.5pt
   */
   public String printInLevelOrder()
   {
       String content = "";
       /*
       * Add items from the tree to content one level at a time
       * No line breaks are required between levels
       * Ensure method runs in O(N) - does not revisit any node
       */
       return content;
   }
   /*
   * Grading:
   * Correctly compares the structure of both trees - 3pts
   */
   public boolean visuallyIdentical(A4BST rhs)
   {
       /*
       * Check if the structure of the local tree and the rhs tree are identical
       * This means they have the same left/right connections
       * This means there are no extra connections in either tree
       * The values at each position do not need to match, only the structure of the tree
       * Think about if you drew both trees on paper, would they visually look the same (besides values)
       */
       return false;
   }
  
   private Node root;

   public A4BST()
   {
       root = null;
   }

   public String printTree()
   {
       return printTree(root);
   }
   private String printTree(Node current)
   {
       String content = "";
       if(current != null)
       {
           content += "Current:"+current.data.toString();
           if(current.left != null)
           {
               content += "; Left side:"+current.left.data.toString();
           }
           if(current.right != null)
           {
               content += "; Right side:"+current.right.data.toString();
           }
           content+="\n";
           content+=printTree(current.left);
           content+=printTree(current.right);

       }
       return content;
   }
   public String printInOrder()
   {
       return printInOrder(root);
   }
   private String printInOrder(Node current)
   {
       String content = "";
       if(current != null)
       {
           content += printInOrder(current.left);
           content += current.data.toString()+",";
           content += printInOrder(current.right);
       }
       return content;
   }
   public boolean contains(E val)
   {
       Node result = findNode(val, root);

       if(result != null)
           return true;
       else
           return false;
   }
   private Node findNode(E val, Node current)
   {
       //base cases
       if(current == null)
           return null;
       if(current.data.equals(val))
           return current;

       //recursive cases
       int result = current.data.compareTo(val);
       if(result < 0)
           return findNode(val, current.right);
       else
           return findNode(val, current.left);
   }
   public E findMin()
   {
       Node result = findMin(root);
       if(result == null)
           return null;
       else
           return result.data;
   }
   private Node findMin(Node current)//used in findMin and delete
   {
       while(current.left != null)
       {
           current = current.left;
       }
       return current;
   }
   public E findMax()
   {
       Node current = root;
       while(current.right != null)
       {
           current = current.right;
       }
       return current.data;
   }
   public void insert(E val)
   {
       root = insertHelper(val, root);
   }
   public Node insertHelper(E val, Node current)
   {
       if(current == null)
       {
           return new Node(val);
       }
       int result = current.data.compareTo(val);
       if(result < 0)
       {
           current.right = insertHelper(val, current.right);
       }
       else if(result > 0)
       {
           current.left = insertHelper(val, current.left);
       }
       else//update
       {
           current.data = val;
       }
       return current;
   }
   public void remove(E val)
   {
       root = removeHelper(val, root);
   }
   private Node removeHelper(E val, Node current)
   {
       if(current.data.equals(val))
       {
           if(current.left == null && current.right == null)//no children
           {
               return null;
           }
           else if(current.left != null && current.right != null)//two children
           {
               Node result = findMin(current.right);
               result.right = removeHelper(result.data, current.right);
               result.left = current.left;
               return result;
           }
           else//one child
           {
               return (current.left != null)? current.left : current.right;
           }
       }
       int result = current.data.compareTo(val);
       if(result < 0)
       {
           current.right = removeHelper(val, current.right);
       }
       else if(result > 0)
       {
           current.left = removeHelper(val, current.left);
       }
       return current;
   }


   private class Node
   {
       E data;
       Node left, right;
       public Node(E d)
       {
           data = d;
           left = null;
           right = null;
       }
   }

}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


public class A4Driver {

   public static void main(String[] args) {
       A4BST<Integer> tree1 = new A4BST<>();
       tree1.insert(5);
       tree1.insert(3);
       tree1.insert(1);
       tree1.insert(2);
       tree1.insert(9);
       tree1.insert(10);
       tree1.insert(25);
       A4BST<Integer> tree2 = new A4BST<>();
       tree2.insert(8);
       tree2.insert(5);
       tree2.insert(1);
       tree2.insert(3);
       tree2.insert(15);
       tree2.insert(20);
       tree2.insert(25);
       A4BST<Integer> tree3 = new A4BST<>();
       tree3.insert(1);
       tree3.insert(2);
       tree3.insert(3);
       tree3.insert(5);
       tree3.insert(9);
       tree3.insert(10);
       tree3.insert(25);
       System.out.println(tree1.printInLevelOrder());//5, 3, 9, 1, 10, 2, 25
       System.out.println(tree2.printInLevelOrder());//8, 5, 15, 1, 20, 3, 25
       System.out.println(tree3.printInLevelOrder());//1, 2, 3, 4, 5, 9, 10, 25
       System.out.println(tree1.visuallyIdentical(tree2));//true
       System.out.println(tree1.visuallyIdentical(tree3));//false
  
  

   }

}

In: Computer Science

Write a C++ main program that has the following 5 short independent segments. 6. Show the...

Write a C++ main program that has the following 5 short independent segments.

6. Show the results of the following power function: pow(-2., 3), pow(-2., 3.0) , pow(-2., 3.00000000001)

7. Show the memory size of the following constants 1. , 1.F, 1 , '1' , and "1"

8. Display 1./3. using 20 digits and show the correct and incorrect digits

9. Display all printable characters of the ASCII table in 3 columns: first column: 32-63, second column: 64-95, third column: 96-127. Each column must include the numeric value and the corresponding character. Following is an example of one of 32 rows in the ASCII table: 33 ! 65 A 97 a

10. Compute sqrt(2.) using your own program for square root function.

In: Computer Science

Design and configure the Star Topology in Packet Tracer with following requirements. • 4 PCs •...

Design and configure the Star Topology in Packet Tracer with following requirements.

• 4 PCs
• 1 SWITCH
• Connection Cable

In: Computer Science

Write a C++ main program that has the following 5 short independent segments. 1. Show that...

Write a C++ main program that has the following 5 short independent segments.

1. Show that for unsigned int a,b and a>0, b>0, we can get a+b < a

2. Show that for int a,b and a>0, b>0, we can get a+b < 0

3. Show that for int a,b and a 0

4. Show that for double x and x>0 we can get 1. + x = = 1.

5. Show that for double a,b,c in some cases (a+b)+c != (c+b)+a

In: Computer Science

A shell script foo contains the statement echo “$PATH $x”. Now define x=5 at the prompt,...

A shell script foo contains the statement echo “$PATH $x”. Now define x=5 at the prompt, and then run the script. Explain your observations and how you can rectify the behavior.

In: Computer Science

Write a program that simulates the flipping of a coin n times, where n is specified...

Write a program that simulates the flipping of a coin n times, where n is specified by the user. The program should use random generation to flip the coin and each result is recorded. Your program should prompt the user for the size of the experiment n, flip the coin n times, display the sequence of Heads and Tails as a string of H (for Head) and T (for Tail) characters, and display the frequencies of heads and tails in the experiment. Use functions for full credit.

In: Computer Science

You are to name your package assign1 and your file Palindrome.java. Palindrome Class Palindrome - testString...

You are to name your package assign1 and your file Palindrome.java.

Palindrome Class

Palindrome

- testString : String

+ Palindrome (String)

+ isPalindrome (): boolean

The method isPalindrome is to determine if a string is a palindrome. A palindrome, for this assignment, is defined as a word or phrase consisting of alphanumeric characters that reads the same frontwards and backwards while ignoring cases, punctuation and white space. If there are no alphanumeric characters, the string is considered a palindrome. The method should return true if it is a palindrome and false otherwise.

Notice – there is no main, no input and no output for this assignment. You are limited to the following Java library classes.

- String
- Character

Here are the restrictions on this method. Up to 20% penalty if not followed.

1. You may NOT return from the inside of a loop.
2. You may NOT break from the inside of a loop.
3. You may use ONLY ONE loop (either while or do-while).

4. You may NOT copy the String to another String.
5. You may NOT process the String more than one time (only make one pass

through it).
6. You must STOP processing as early as possible (when you find that it is or is not

a palindrome). In other words, using a for loop is not a good solution.

In: Computer Science

C# programming Create a class called A with private integer field x, protected integer field y,...

C# programming

Create a class called A with private integer field x, protected integer field y, public integer field z. Create a class B derived from class A with public integer field d and protected integer field e and private field f.

  1. Write a main (in a THIRD class called Program) that create an object B and assign all publicly accessible fields of the object with value of 1. Which fields will have a value of 1?
  2. Create a method Foo in B and assign all fields accessible to the method with value of 2. Which fields will have a value of 2 now?
  3. If I try to define public integer fields x, y and z in class B, what will happen? Which one will cause a compilation warning? Why do you think the result is like that?

Write your answer to all three questions below:

In: Computer Science

Python program to simulate estimate the probability that a random chord on a unit-circle (radius one),...

Python program to simulate estimate the probability that a random chord on a unit-circle (radius one), exceeds the radius of the circle? Repeat the experiment of generating random chords 1,000 times. Record the estimate of the probability that the chord length exceeds the radius

Please use comments to help explain

In: Computer Science

Programming language: Java If any more information is needed please let me know exactly what you...

Programming language: Java

If any more information is needed please let me know exactly what you need.

Though there are a bunch of files they are small and already done. Modify the driver file ,Starbuzz coffee, to be able to order each blend and be able to add each condiment to each of the blends. The price should be set accordingly. Be able to: order 1 of each type of beverage, add multiple toppings to each ordered beverage and use each condiment at least once.

Beverage.java:

public abstract class Beverage {
   String description = "Unknown Beverage";
  
   public String getDescription() {
       return description;
   }

   public abstract double cost();
}

CondimentDecorator.java:

public abstract class CondimentDecorator extends Beverage {
   public abstract String getDescription();
}

DarkRoast.java:

public class DarkRoast extends Beverage {
   public DarkRoast() {
       description = "Dark Roast Coffee";
   }

   public double cost() {
       return .99;
   }
}

Decaf.java:

public class Decaf extends Beverage {
   public Decaf() {
       description = "Decaf Coffee";
   }

   public double cost() {
       return 1.05;
   }
}

Espresso.java:

public class Espresso extends Beverage {
  
   public Espresso() {
       description = "Espresso";
   }
  
   public double cost() {
       return 1.99;
   }
}

HouseBlend.java:

public class HouseBlend extends Beverage {
   public HouseBlend() {
       description = "House Blend Coffee";
   }

   public double cost() {
       return .89;
   }
}

Caramel.java:

public class Caramel extends Beverage {
   public Caramel() {
       description = "Caramel Coffee";
   }

   public double cost() {
       return 1.35;
   }
}

Chocolate.java:

public class Chocolate extends CondimentDecorator {
   Beverage beverage;

   public Chocolate(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Chocolate";
   }

   public double cost() {
       return .20 + beverage.cost();
   }
}

Cinnamon.java:

public class Cinnamon extends CondimentDecorator {
   Beverage beverage;

   public Cinnamon(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Cinnamon";
   }

   public double cost() {
       return .15 + beverage.cost();
   }
}

Milk.java:

public class Milk extends CondimentDecorator {
   Beverage beverage;

   public Milk(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Milk";
   }

   public double cost() {
       return .10 + beverage.cost();
   }
}

Mint.java:

public class Mint extends CondimentDecorator {
   Beverage beverage;

   public Mint(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Mint";
   }

   public double cost() {
       return .15 + beverage.cost();
   }
}

Mocha.java:

public class Mocha extends CondimentDecorator {
   Beverage beverage;

   public Mocha(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Mocha";
   }

   public double cost() {
       return .20 + beverage.cost();
   }
}

Soy.java:

public class Soy extends CondimentDecorator {
   Beverage beverage;

   public Soy(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Soy";
   }

   public double cost() {
       return .15 + beverage.cost();
   }
}

Whip.java:

public class Whip extends CondimentDecorator {
   Beverage beverage;

   public Whip(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Whip";
   }

   public double cost() {
       return .10 + beverage.cost();
   }
}

StarbuzzCoffee.java:

public class StarbuzzCoffee {

   public static void main(String args[]) {
       Beverage beverage = new Espresso();
       System.out.println(beverage.getDescription()
               + " $" + beverage.cost());
              
       Beverage beverage1 = new Decaf();
       beverage1 = new Soy(beverage1);
       beverage1 = new Mocha(beverage1);
       beverage1 = new Whip(beverage1);
       beverage1 = new Cinnamon(beverage1);
       beverage1 = new Mint(beverage1);
       beverage1 = new Chocolate(beverage1);
       System.out.println(beverage1.getDescription()
               + " $" + beverage1.cost());

       Beverage beverage2 = new DarkRoast();
       beverage2 = new Soy(beverage2);
       beverage2 = new Mocha(beverage2);
       beverage2 = new Whip(beverage2);
       beverage2 = new Cinnamon(beverage2);
       beverage2 = new Mint(beverage2);
       beverage2 = new Chocolate(beverage2);
       System.out.println(beverage2.getDescription()
               + " $" + beverage2.cost());

       Beverage beverage3 = new HouseBlend();
       beverage3 = new Soy(beverage3);
       beverage3 = new Mocha(beverage3);
       beverage3 = new Whip(beverage3);
       beverage3 = new Cinnamon(beverage3);
       beverage3 = new Mint(beverage3);
       beverage3 = new Chocolate(beverage3);
       System.out.println(beverage3.getDescription()
               + " $" + beverage3.cost());
      
       Beverage beverage4 = new Hazelnut();
       beverage4 = new Soy(beverage4);
       beverage4 = new Mocha(beverage4);
       beverage4 = new Whip(beverage4);
       beverage4 = new Cinnamon(beverage4);
       beverage4 = new Mint(beverage4);
       beverage4 = new Chocolate(beverage4);
       System.out.println(beverage4.getDescription()
               + " $" + beverage4.cost());  

       Beverage beverage5 = new Caramel();
       beverage5 = new Soy(beverage5);
       beverage5 = new Mocha(beverage5);
       beverage5 = new Whip(beverage5);
       beverage2 = new Cinnamon(beverage5);
       beverage2 = new Mint(beverage5);
       beverage2 = new Chocolate(beverage5);
       System.out.println(beverage5.getDescription()
               + " $" + beverage5.cost());
   }
}

In: Computer Science

C# programming Create a class called A with private integer field x, protected integer field y,...

C# programming

Create a class called A with private integer field x, protected integer field y, public integer field z. Create a class B derived from class A with public integer field d and protected integer field e and private field f.

  1. Write a main (in a THIRD class called Program) that create an object B and assign all publicly accessible fields of the object with value of 1. Which fields will have a value of 1?
  2. Create a method Foo in B and assign all fields accessible to the method with value of 2. Which fields will have a value of 2 now?
  3. If I try to define public integer fields x, y and z in class B, what will happen? Which one will cause a compilation warning? Why do you think the result is like that?

Write your answer to all three questions below:

In: Computer Science

Using C++, Create a singly Linked List of patients list so that you can sort and...

Using C++, Create a singly Linked List of patients list so that you can sort and search the list by last 4 digits of the patient's Social Security number. Implement Node insertion, deletion, update and display functionality in the Linked List.

Each patient's record or node should have the following data:

Patient Name:

Age:

Last 4 digits of Social Security Number:

The program should first display a menu that gives the user the option to:

1) Add a Patient's record (After adding one patient the user should be prompted: Do you want to add another patient's record? 1 for Yes and 0 for No)

2) Modify a Patient's record ((After modifying/updating one patient the user should be prompted: Do you want to add modify patient's record? 1 for Yes and 0 for No)

3) Delete a Patient's Record ((After deleting one patient the user should be prompted: Do you want to delete another patient's record? 1 for Yes and 0 for No)

4) Display a Patient's record

In: Computer Science

Why is the SISP important for developing a RFP?

Why is the SISP important for developing a RFP?

In: Computer Science

using python 3 2. Write a python program that finds the numbers that are divisible by...

using python 3

2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000.

3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False.

4. In your main Python program write a for loop that counts from 1 to 1000 and calls this YesNo function inside the for loop and will print "The number xx is divisible by both 2 and 7 but not 70, or that are divisible by 57" if the YesNo function returns True. Otherwise it prints nothing. Note the print statement also prints the number where the xx is above.

In: Computer Science