Question

Convert into pseudo-code for below code =============================== class Main {    public static void main(String args[])...

Convert into pseudo-code for below code

===============================

class Main
{
   public static void main(String args[])
   {
       Scanner s=new Scanner(System.in);
       ScoresCircularDoubleLL score=new ScoresCircularDoubleLL();
       while(true)
       {
           System.out.println("1--->Enter a number\n-1--->exit");
           System.out.print("Enter your choice:");
           int choice=s.nextInt();
           if(choice!=-1)
           {
               System.out.print("Enter the score:");
               int number=s.nextInt();
               GameEntry entry=new GameEntry(number);
               if(number!=-1)
               {
                   if(score.getNumberOfEntries()==10)       // if linkedlist has more than 10 nodes, remove min score and add new score
                   {
                       int minValue=score.getMinimumValue();   // function to get minValue
                       if(minValue<number)                       // if min score is greater than given score, then dont add new node
                       {
                           int minValueIndex=score.getMinimumValueIndex();   // function to get minValueIndex
                           score.remove(minValueIndex);           // remove minValueIndex node
                           score.add(entry);                       // add the new node
                       }
                   }
                   else
                   {
                       score.add(entry);           // if linked list has less than 10 nodes, add the current node
                   }
               }
               score.printScore();                   // method to print entries in linked lists
           }
           else
           {
               break;
           }
       }
   }
  
}

class ScoresCircularDoubleLL
{
   CircularDoubleLinkedList head=null;
   int noOfEntries=0;
   public void add(GameEntry e)
   {
       CircularDoubleLinkedList tempNode=new CircularDoubleLinkedList(e);
       if(head==null)           // if list is empty add new node as head
       {
           head=tempNode;
           head.left=head;
           head.right=head;
       }
       else
       {
           CircularDoubleLinkedList node=head;
           while(node.right!=head)       // else add new node at tail
           {
               node=node.right;
           }
           node.right=tempNode;
           tempNode.left=node;
           tempNode.right=head;
           head.left=tempNode;
       }
       noOfEntries++;
   }
    public GameEntry remove(int minValueIndex)
    {
       CircularDoubleLinkedList node=head;
       if(minValueIndex==0)           // if value to be removed is head, remove head
       {
           head=head.right;
       }
       else
       {
           CircularDoubleLinkedList prevNode=head;       // else remove index 'i' element
           node=head.right;
           int index=1;
           while(index!=minValueIndex)
           {
               index++;
               prevNode=node;
               node=node.right;
           }
           prevNode.right=node.right;
           if(node.right!=null)
               node.right.left=prevNode;
       }
       noOfEntries--;
       return node.node;
    }
    public int getMinimumValueIndex()
    {
        CircularDoubleLinkedList node=head;
        int minValue=Integer.MAX_VALUE;
        int index=0,i=0;
       do
       {
           if(node.node.score<minValue)
           {
               minValue=node.node.score;
               index=i;
           }
           node=node.right;
           i++;
       }while(node!=head);
       return index;
    }
    public int getMinimumValue()
    {
        CircularDoubleLinkedList node=head;
        int minValue=Integer.MAX_VALUE;
       do
       {
           if(node.node.score<minValue)
           {
               minValue=node.node.score;
           }
           node=node.right;
       }while(node!=head);
       return minValue;
    }
    public int getNumberOfEntries()
    {
        return noOfEntries;
    }
    public void printScore()
    {
        CircularDoubleLinkedList node=head;
       do
       {
           System.out.print(node.node.score+" ");
           node=node.right;
       }while(node!=head);
       System.out.println();
    }
}
class CircularDoubleLinkedList
{
   GameEntry node;
   CircularDoubleLinkedList left;
   CircularDoubleLinkedList right;
   CircularDoubleLinkedList(GameEntry node)
   {
       this.node=node;
   }
}

==============================

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This program is simply to take care of all the scores in the game .....

class Main
{
   public static void main(String args[])

{

here we are dynamically giving the position of the score and also to handle that score e are making a double linked list to store that scores by making the object of the class CircularDoubleLinkedList.

while(true)

{

here it will ask for our choice for the game between 1 to n-1.

if the number of game-entry exceeded to 10 then it will find out the least game entry through the function and it will remove it. then it will add the score in the respective game-entry and will print the scpre otherwise it will break.

}

}

}

class ScoresCircularDoubleLL

{

this class simply add scores of the game as an entry as node to the double linked list ..the main idea behind using double linked list is we can traveerse in both directions.

if the list will be empty then it wiill simply add the node by connecting it with the head node else it will be connected with the last node .

}

public GameEntry remove(int minValueIndex)

{

this function is to remove the minimum valued game entry and it will chek wether it is header nide or any 'i'th index node then it will remove that entry from the game entry.

the minimum entry is found by the finding and minimum value and then its index and then it is removed through that index.

}

public int getMinimumValueIndex()
{

it is use to find the minimum valued index of the minimum value so that it can be removed and to know its index we have to find the minum value and that can be found through another function.

}

public int getMinimumValue()
{

it will give the minimum value so that its index could be found and hence can be removed.

}

public int getNumberOfEntries()
{
this function returns the number of game entries entered by the user,
}

public void printScore()
{

this function is use to print the scores in the particular game entry with the help of DoubleLinkedList.

}

Class CircularDoubleLinkedList

{

here a double linked list is created to store the game entry as well as the score in each game entry ...

}

Add a comment
Know the answer?
Add Answer to:
Convert into pseudo-code for below code =============================== class Main {    public static void main(String args[])...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args)...

    Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn);    else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...

  • //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args )...

    //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args ) { Scanner in = new Scanner( System.in ); LinkedList teamList = new LinkedList(); final int TEAM_SIZE = Integer.valueOf(in.nextLine()); for (int i=0; i<TEAM_SIZE; i++) { String newTeamMember = in.nextLine(); teamList.append(newTeamMember); } while (in.hasNext()) { String removeMember = in.nextLine(); teamList.remove(removeMember); }    System.out.println("FINAL TEAM:"); System.out.println(teamList); in.close(); System.out.print("END OF OUTPUT"); } } =========================================================================================== //PoD import java.util.NoSuchElementException; /** * A listnked list is a sequence of nodes with...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args)...

    Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...

  • BST JAVA FILE import java.util.*; public class BST <E extends Comparable <E>> {    private TreeNode<E>...

    BST JAVA FILE import java.util.*; public class BST <E extends Comparable <E>> {    private TreeNode<E> overallRoot;    public BST() {        overallRoot = null;    }    // ************ ADD ************ //    public void add(E addThis) {        if (overallRoot == null) {            overallRoot = new TreeNode<>(addThis);        } else {            add(overallRoot, addThis);        }    }    private TreeNode<E> add(TreeNode<E> node, E addThis) {        if...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • Java Programming: The following is my code: public class KWSingleLinkedList<E> {    public void setSize(int size)...

    Java Programming: The following is my code: public class KWSingleLinkedList<E> {    public void setSize(int size)    {        this.size = size;    }    /** Reference to list head. */    private Node<E> head = null;    /** The number of items in the list */    private int size = 0;       /** Add an item to the front of the list.    @param item The item to be added    */    public void addFirst(E...

  • public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc...

    public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc = new Scanner(System.in);         String choice = "y";         while (choice.equalsIgnoreCase("y")) {             // get the input from the user             System.out.println("DATA ENTRY");             double monthlyInvestment = getDoubleWithinRange(sc,                     "Enter monthly investment: ", 0, 1000);             double interestRate = getDoubleWithinRange(sc,                     "Enter yearly interest rate: ", 0, 30);             int years = getIntWithinRange(sc,                     "Enter number of years: ", 0, 100);             System.out.println();            ...

  • import java.util.Scanner; public class Client{ public static void main(String args[]){    Coin quarter = new Coin(25);...

    import java.util.Scanner; public class Client{ public static void main(String args[]){    Coin quarter = new Coin(25); Coin dime = new Coin(10); Coin nickel = new Coin(5);    Scanner keyboard = new Scanner(System.in);    int i = 0; int total = 0;    while(true){    i++; System.out.println("Round " + i + ": "); quarter.toss(); System.out.println("Quarter is " + quarter.getSideUp()); if(quarter.getSideUp() == "HEADS") total = total + quarter.getValue();    dime.toss(); System.out.println("Dime is " + dime.getSideUp()); if(dime.getSideUp() == "HEADS") total = total +...

  • P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList()...

    P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList() { header = null; } public final Node Search(int key) { Node current = header; while (current != null && current.item != key) { current = current.link; } return current; } public final void Append(int newItem) { Node newNode = new Node(newItem); newNode.link = header; header = newNode; } public final Node Remove() { Node x = header; if (header != null) { header...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT