Question

In: Computer Science

Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public...

Convert this pseudo code program into sentences.

import java.util.ArrayList;
import java.util.Collections;
class Bulgarian
{
   public static void main(String[] args)
   {
       max_cards=45;
       arr->new ArraryList
       col=1;
       card=0;
       left=max_cards;
       do{
           col->random number
           row->new ArrayList;
           for i=0 to i<col
           {
               card++
               add card into row
           }
           add row into arr
           left=max_cards-card;
       }while(card<max_cards);
       finish->false
       while(!finish)
       {
           for i=0 to arr.size()
               remove one card from each row
           add row into arr
           size->new ArrayList;
           for i=0 to i<arr.size()
               add arr[i] into size
           sort(size)
           for i=1 to size.size()
               if ith element is equals to (i-1)+1
                   finish->true
               else
                   finish->false
           for i=0 to i<arr.size()
               print->arr elements
       }
   }
}

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

Bulgarian.java

package staticclasses;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class Bulgarian
{
public static void main(String[] args)
{
int max_cards=45;
ArrayList<ArrayList<Integer>> arr = new ArrayList<>();
int col=1;
int card=0;
int left=max_cards;
Random rand = new Random();
do{
   col = rand.nextInt(max_cards);
   ArrayList<Integer> row = new ArrayList<>();
for(int i=0;i<col;i++)
{
card++;
row.add(card);
}
arr.add(row);
left=max_cards-card;
}while(card<max_cards);
boolean finish=false;
while(!finish)
{
for(int i=0;i<arr.size();i++) {
   arr.get(i).remove(0);
    arr.add(arr.get(i));
}

ArrayList<ArrayList<Integer>> size =new ArrayList<>();
for(int i=0;i<arr.size();i++)
   size.add(arr.get(i));

sort(size);

for(int i=1;i<size.size();i++)
if (size.get(i)==size.get((i-1)+1))
finish=true;
else
finish=false;
for(int i=0;i<arr.size();i++)
   System.out.println(arr.get(i));
}
}
}


Related Solutions

Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution {...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap labs = new HashMap(); while (true) { System.out.println("Choose operation : "); System.out.println("1. Create a Lab"); System.out.println("2. Modify a Lab"); System.out.println("3. Delete a Lab"); System.out.println("4. Assign a pc to a Lab"); System.out.println("5. Remove a pc from a Lab"); System.out.println("6. Quit"); int choice = sc.nextInt(); String name=sc.nextLine(); switch (choice) { case 1:...
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public...
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public class CourseeCOM616 {        private String courseName;     private String[] studentsName = new String[1];     private String studentId;        private int numberOfStudents;        public CourseeCOM616(String courseName) {         this.courseName = courseName;     }     public String[] getStudentsName() {         return studentsName;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getStudentId() {         return studentId;    ...
This is the code that needs to be completed... import java.util.ArrayList; import java.util.Collections; /** * Write...
This is the code that needs to be completed... import java.util.ArrayList; import java.util.Collections; /** * Write a description of class SpellChecker here. * * @author (your name) * @version (a version number or a date) */ public class SpellChecker { private ArrayList words; private DictReader reader; /** * Constructor for objects of class SpellChecker */ public SpellChecker() { reader = new DictReader("words.txt"); words = reader.getDictionary(); } /** * This method returns the number of words in the dictionary. * Change...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task>...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task> list;//make private array public ToDoList() { //this keyword refers to the current object in a method or constructor this.list = new ArrayList<>(); } public Task[] getSortedList() { Task[] sortedList = new Task[this.list.size()];//.size: gives he number of elements contained in the array //fills array with given values by using a for loop for (int i = 0; i < this.list.size(); i++) { sortedList[i] = this.list.get(i);...
Please convert this java program to a program with methods please. import java.io.*; import java.util.*; public...
Please convert this java program to a program with methods please. import java.io.*; import java.util.*; public class Number{ public static void main(String[] args) {    Scanner scan = new Scanner(System.in); System.out.println("Enter 20 integers ranging from -999 to 999 : "); //print statement int[] array = new int[20]; //array of size 20 for(int i=0;i<20;i++){ array[i] = scan.nextInt(); //user input if(array[i]<-999 || array[i]>999){ //check if value is inside the range System.out.println("Please enter a number between -999 to 999"); i--; } } //...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's...
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's cart. Items of Type T can be added * or removed from the cart. A hashmap is used to keep track of the number of items * that have been added to the cart example 2 apples or 4 shirts. * @author Your friendly CS Profs * @param -Type of items that will be placed in the Cart. */ public abstract class AbstractCart {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT