Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help bubble sorting this code. I know how to do a regular sort, but I can\'

ID: 3602662 • Letter: N

Question

Need help bubble sorting this code. I know how to do a regular sort, but I can't wrap my head around it. If you are just going to post the sort code don't please.

Spell spe = new Spell();
spe.Name = w.ReadLine();
spe.Attk = num.Next(1,11);
spe.Weight = weight;
wspe.Apm = spe.Attk * (11 - weight);
array[x] = spe;

Potion pot = new Potion();
pot.Name = ar.ReadLine();
pot.Weight = weight;
pot.Def = num.Next(1,11);
pot.Dpm = Armo.Def * (11 - weight);
array[x] = pot;

Item temp;
int count=0;
do
{
int dmgvalue=0;
int potionvalue=0;

for (int x = 0; x < array.Length - 1; x++)
{
if (array[x+1] is Spell)
{
dmgvalue = ((Spell)array[x+1]).Dmg;
}
else
{
potionvalue = ((Potion)array[x+1]).Heal;
}
}
for (int y = 0; y < array.Length - 1; y++)
{
if (array[y] is Spell)

if (((Spell)array[y]).Dmg > dmgvalue)
{
temp = array[y];
array[y] = array[y + 1];
array[y + 1] = temp;
Console.WriteLine(" Display: {0}", temp);
}
}
else
{
if (((Potion)array[y]).Heal > potionvalue)
{
temp = array[y];
array[y] = array[y + 1];
array[y + 1] = temp;

}
}
}
count++;
  
for(int x=0;x<10;x++)
{
array[x].display();
}   
  
}while (count ==10);

Explanation / Answer

import java.io.File;

importjava.io.IOException;

import java.util.Scanner;

public class SpellCheck {

public static void main(String[] args) throwsIOException {

Scanner dictionary = new Scanner(newFile(args[0]));

Scanner size = dictionary;

int numWords = 0;

while (size.hasNext()) {

numWords++;

size.next();

}

int count = 0;

String[] words = newString[numWords];

while (dictionary.hasNext()) {

words[count] =dictionary.next();

count++;

}

System.out.println("What file doyou wish to spell check? Or type quit when done.");

Scanner document = newScanner(System.in);

String w = document.next();

String [] mispelled = new String[10];

while (!w.equalsIgnoreCase("quit")){

Scanner in = newScanner(new File(w));

int j;

while (in.hasNext()){

Stringword = in.next();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote