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

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.
(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 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   ...
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...
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.
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Write a java program that does the following: a) The user will enter data such as...
Write a java program that does the following: a) The user will enter data such as client name and client balance. The user can stop inputting data by entering "stop". The program should store the user inputs as a data member of an array. The type of this array is a class named ClientData. Below the output should be displayed by the program. The parts in bold are inputs from the user and not hard coded in the program Client...
Using c# programming language Write a program that mimics a lottery game. Have the user enter...
Using c# programming language Write a program that mimics a lottery game. Have the user enter 3 distinct numbers between 1 and 10 and match them with 3 distinct, randomly generated numbers between 1 and 10. If all the numbers match, then the user will earn $10, if 2 matches are recorded then the user will win $3, else the user will lose $5. Keep tab of the user earnings for, let say 5 rounds. The user will start with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT