Question

In: Computer Science

using java language "Data Structures" I have to write program which stores string entered by user...

using java language "Data Structures"

I have to write program which stores string entered by user into cursor array implementation

here is the code

public static void main(String[] args) {

CursorArray sorted =new CursorArray();//the strings must added here how can i store them
         
       String []inputs = new String[50];
          
       for (int i=0; i< 50; i++) {
           System.out.println("Enter the words you want to sort and use exit to stop");
           if(input.next().equals("exit"))
               break;
       inputs[i] = input.nextLine();
       }
}   
      

you can put the code of reading in a method

and this is part of cursor class

public class CursorArray {

   Node[] cursorArray = new Node[10];

   public int initialization() {

       for (int i = 0; i < cursorArray.length - 1; i++) {

           cursorArray[i] = new Node(null, i + 1);
       }
       cursorArray[cursorArray.length - 1] = new Node(null, 0);
       return 0;
   }

   public int malloc() {
       int p = cursorArray[0].next;
       cursorArray[0].next = cursorArray[p].next;
       return p;
   }

   public void free(int p) {
       cursorArray[p] = new Node(null, cursorArray[0].next);
       cursorArray[0].next = p;
   }

}

public class Node {
  
  
   String data;
   int next; //index

   public Node(String data, int next) {
       this.data = data;
       this.next = next;
}

}

Solutions

Expert Solution

as per the requirements of question, the question had been answered.

only taking user input and storing the strings in CursorArray by initialization method

Raw_code:

Driver.java:

import java.util.Scanner; // import Scanner class for taking user input

public class Driver{
public static void main(String[] args){
// creating Scanner object on standard input stream
Scanner input = new Scanner(System.in);
CursorArray sorted = new CursorArray();//the strings must added here how can i store them

String []inputs = new String[50];

for (int i=0; i< 50; i++) {
System.out.println("Enter the words you want to sort and use exit to stop");
if(input.next().equals("exit"))
break;
inputs[i] = input.nextLine();
}
// calling initialization method of CursorArray object with inputs(string array) as argument   
sorted.initialization(inputs);
}
}

// if you want to added the strings through constructor of CursorArray then just replace method name intialization to CursorArray and truncate the return type int


Related Solutions

Instructions: Create a Java program that reads a string entered by the user and then determines...
Instructions: Create a Java program that reads a string entered by the user and then determines and prints how many of each lowercase vowel (a, e, i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also, count and print the number of non-vowel characters. Example: User enters: "This house is beautiful." a: 1 e: 2 i: 3 o: 1 u: 2 non-vowel:10
Using C# programming language, Write a program that sort three numbers entered by the user using...
Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
(JAVA) We will write a program to check the spelling of the word entered by user,...
(JAVA) We will write a program to check the spelling of the word entered by user, using data from a dictionary, which is text file. The program will ask user to enter a word for spell check, and then check in the text file (dictionary.txt) if the word exists. (The dictionary.txt file is provided) If the word exists in text file, the output will be “Word is correctly spelled”. If the word doesn’t exist in the text file, program will...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by that candidate. The program should then output each candidates name, votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is as follow Johnson    5000 25.91 miller    4000   ...
How would I write a program for C++ that checks if an entered string is an...
How would I write a program for C++ that checks if an entered string is an accepted polynomial and if it is, outputs its big-Oh notation? Accepted polynomials can have 3 terms minimum and no decimals in the exponents.
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT