Rewrite following Java program using use List and not arrays.
public class Shoes {
private String name;
private int size;
private String model;
public Shoes() {
}
public Shoes(String name, int size, String model) {
this.name = name;
this.size = size;
this.model = model;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
@Override
public String toString() {
return "name='" + name + '\'' + ", size=" + size + ", model='" + model + '\'';
}
public static void main(String[] args) {
Shoes[] shoes = new Shoes[5];
shoes[0] = new Shoes("Nike1", 9, "Nike");
shoes[1] = new Shoes("ASICS2", 12, "ASICS");
shoes[2] = new Shoes("Adidas8", 11, "Adidas");
shoes[3] = new Shoes("Saucony7", 6, "Saucony");
shoes[4] = new Shoes("Brooks5", 8, "Brooks");
for (int i = 0; i < shoes.length; i++) {
System.out.println(shoes[i]);
}
}
}In: Computer Science
Every time I attempt to execute this, I get an
inputmismatchexception, which looks like this:
Oops! Read Exception: java.util.InputMismatchExceptionInitial
input:
Input sorted by grade
Input sorted selection
This is my code.
import java.util.*;
import java.io.*;
import java.io.PrintStream;
public class jack {
PrintStream prt = System.out;
int n;
int i;
int j;
double grade[];
String name[];
jack() {
try {
Scanner inf = new Scanner(System.in);
n=inf.nextInt();
inf.nextLine();
grade=new double[n];
name = new String[n];
for (int i=0; i<n; i++){
name[i] = inf.next();
inf.nextLine();
grade[i] = inf.nextDouble();
inf.nextLine();
}
inf.close();
} catch (Exception e) {
prt.printf("\nOops! Read Exception: %s", e);
}
}
private void print() {
for(int i=0; i<n; i++)
{
System.out.println(name[i]+" "+grade[i]);
}
System.out.println();
}
private void sortbyname(){
String minStudent;
int index;
for(int i=0;i<n-1;i++){
minStudent=name[i];
index=i;
for(int j=i+1; j<n; j++){
if(name[j].compareTo(minStudent)<0)
{
minStudent = name[j];
index =j;
}
}
String beforewrd = name[index];
name[index]=name[i];
name[i]=beforewrd;
}
}
private void sortbygrade(){
for(int i=0;i<n;i++){
int index=i;
for(int j=i+1; j<n; j++){
if(grade[j]<grade[i]){
index = j;
}
}
double smallNum = grade[index];
grade[index] = grade[i];
grade[i]=smallNum;
}
}
public static void main(String args[]) throws Exception{
jack p = new jack ();
System.out.print("Initial input:");
p.print();
p.sortbyname();
System.out.print("Input sorted by grade");
p.print();
p.sortbygrade();
System.out.print("Input sorted selection");
p.print();
}
}
In: Computer Science
Which is the correct name of the following molecule?

In: Chemistry
Name the 3 branches of government AND their roles:
In: Economics
Define and name a Duopoly, are they a Monopoly and why they are or are not? Explain what a Cartel is, and why are they not illegal broadly speaking? Please define in economic terms.
In: Economics
Name the four lobes of the cerebral cortex. What functions do they perform.
In: Psychology
Name and explain the steps in the marketing process?
In: Economics