I am attempting to create a program that asks for the user to input the name of 6 items out of a large list. It then totals up all the attributes of said items and displays the total of all the attributes as well as the cost. The only way I can see doing this would require a huge amount of if and else if statements along with a for loop. With the amount of items I need to use it would be atleast 1000 lines long of if and else statements and that would take a whole lot of time to write out.
Here is a sample of my code
import java.util.Scanner;
public class MyProgram
{
public static void main(String[] args)
{
Scanner one = new Scanner(System.in);
System.out.print("Champion: ");
String champion = one.next();
System.out.print("Item 1: ");
String item1 = one.next();
System.out.print("Item 2: ");
String item2 = one.next();
System.out.print("Item 3: ");
String item3 = one.next();
System.out.print("Item 4: ");
String item4 = one.next();
System.out.print("Item 5: ");
String item5 = one.next();
System.out.print("Item 6: ");
String item6 = one.next();
int totalhealth = 0;
int totalad = 0;
int totalap = 0;
int totalarmor = 0;
int totalmr = 0;
int totalcdr = 0;
int totalmana = 0;
int totalcstr= 0;
int totalls = 0;
int totalatcksp = 0;
int totalcost = 0;
for(int i = 0; i < 6; i++)
{
int itemhealth = 0;
int itemad = 0;
int itemap = 0;
int itemarmor = 0;
int itemmr = 0;
int itemcdr = 0;
int itemmana = 0;
int itemcstr = 0;
int itemls = 0;
int itematcksp = 0;
int itemcost = 0;
if(i == 0)
{
if(item1.equals("abyssal mask"))
{
itemhealth = 350;
itemmana = 300;
itemmr = 55;
itemcdr = 10;
itemcost = 2900;
}
else if (item1.equals("adaptive helm"))
{
itemhealth = 350;
itemmr = 55;
itemcdr = 10;
itemcost = 2800;
}
else if (item1.equals("aegis of the legion"))
{
itemarmor = 30;
itemmr = 30;
itemcost = 1100;
}
else if (item1.equals("aether wisp"))
{
itemap = 30;
itemcost = 850;
}
else if (item1.equals("amplifying tome"))
{
itemap = 20;
itemcost = 435;
}
else if (item1.equals("ancient coin"))
{
itemcdr = 5;
itemcost = 350;
}
else if (item1.equals("archangel's staff"))
{
itemap = 80;
itemmana = 250;
itemcost = 3100;
}
else if (item1.equals("ardent censer"))
{
itemap = 60;
itemcdr = 10;
itemcost = 2300;
}
else if (item1.equals("athene's unholy grail"))
{
itemap= 30;
itemmr = 30;
itemcdr = 10;
itemcost = 2100;
}
else if (item1.equals("b.f.sword"))
{
itemad = 40;
itemcost = 1300;
}
else if (item1.equals("bami's cinder"))
{
itemhealth = 200;
itemcost = 900;
}
}
if(i == 1)
{
if(item2.equals("abyssal mask"))
{
itemhealth = 350;
itemmana = 300;
itemmr = 55;
itemcdr = 10;
itemcost = 2900;
}
else if (item2.equals("adaptive helm"))
{
itemhealth = 350;
itemmr = 55;
itemcdr = 10;
itemcost = 2800;
}
else if (item2.equals("aegis of the legion"))
{
itemarmor = 30;
itemmr = 30;
itemcost = 1100;
}
else if (item2.equals("aether wisp"))
{
itemap = 30;
itemcost = 850;
}
else if (item2.equals("amplifying tome"))
{
itemap = 20;
itemcost = 435;
}
else if (item2.equals("ancient coin"))
{
itemcdr = 5;
itemcost = 350;
}
else if (item2.equals("archangel's staff"))
{
itemap = 80;
itemmana = 250;
itemcost = 3100;
}
else if (item2.equals("ardent censer"))
{
itemap = 60;
itemcdr = 10;
itemcost = 2300;
}
else if (item2.equals("athene's unholy grail"))
{
itemap= 30;
itemmr = 30;
itemcdr = 10;
itemcost = 2100;
}
else if (item2.equals("b.f.sword"))
{
itemad = 40;
itemcost = 1300;
}
else if (item2.equals("bami's cinder"))
{
itemhealth = 200;
itemcost = 900;
}
}
if(i == 2)
{
if(item3.equals("abyssal mask"))
{
itemhealth = 350;
itemmana = 300;
itemmr = 55;
itemcdr = 10;
itemcost = 2900;
}
else if (item3.equals("adaptive helm"))
{
itemhealth = 350;
itemmr = 55;
itemcdr = 10;
itemcost = 2800;
}
else if (item3.equals("aegis of the legion"))
{
itemarmor = 30;
itemmr = 30;
itemcost = 1100;
}
else if (item3.equals("aether wisp"))
{
itemap = 30;
itemcost = 850;
}
else if (item3.equals("amplifying tome"))
{
itemap = 20;
itemcost = 435;
}
else if (item3.equals("ancient coin"))
{
itemcdr = 5;
itemcost = 350;
}
else if (item3.equals("archangel's staff"))
{
itemap = 80;
itemmana = 250;
itemcost = 3100;
}
else if (item3.equals("ardent censer"))
{
itemap = 60;
itemcdr = 10;
itemcost = 2300;
}
else if (item3.equals("athene's unholy grail"))
{
itemap= 30;
itemmr = 30;
itemcdr = 10;
itemcost = 2100;
}
else if (item3.equals("b.f.sword"))
{
itemad = 40;
itemcost = 1300;
}
else if (item3.equals("bami's cinder"))
{
itemhealth = 200;
itemcost = 900;
}
}
if(i == 3)
{
if(item4.equals("abyssal mask"))
{
itemhealth = 350;
itemmana = 300;
itemmr = 55;
itemcdr = 10;
itemcost = 2900;
}
else if (item4.equals("adaptive helm"))
{
itemhealth = 350;
itemmr = 55;
itemcdr = 10;
itemcost = 2800;
}
else if (item4.equals("aegis of the legion"))
{
itemarmor = 30;
itemmr = 30;
itemcost = 1100;
}
else if (item4.equals("aether wisp"))
{
itemap = 30;
itemcost = 850;
}
else if (item4.equals("amplifying tome"))
{
itemap = 20;
itemcost = 435;
}
else if (item4.equals("ancient coin"))
{
itemcdr = 5;
itemcost = 350;
}
else if (item4.equals("archangel's staff"))
{
itemap = 80;
itemmana = 250;
itemcost = 3100;
}
else if (item4.equals("ardent censer"))
{
itemap = 60;
itemcdr = 10;
itemcost = 2300;
}
else if (item4.equals("athene's unholy grail"))
{
itemap= 30;
itemmr = 30;
itemcdr = 10;
itemcost = 2100;
}
else if (item4.equals("b.f.sword"))
{
itemad = 40;
itemcost = 1300;
}
else if (item4.equals("bami's cinder"))
{
itemhealth = 200;
itemcost = 900;
}
}
if(i == 4)
{
if(item5.equals("abyssal mask"))
{
itemhealth = 350;
itemmana = 300;
itemmr = 55;
itemcdr = 10;
itemcost = 2900;
}
else if (item5.equals("adaptive helm"))
{
itemhealth = 350;
itemmr = 55;
itemcdr = 10;
itemcost = 2800;
}
else if (item5.equals("aegis of the legion"))
{
itemarmor = 30;
itemmr = 30;
itemcost = 1100;
}
else if (item5.equals("aether wisp"))
{
itemap = 30;
itemcost = 850;
}
else if (item5.equals("amplifying tome"))
{
itemap = 20;
itemcost = 435;
}
else if (item5.equals("ancient coin"))
{
itemcdr = 5;
itemcost = 350;
}
else if (item5.equals("archangel's staff"))
{
itemap = 80;
itemmana = 250;
itemcost = 3100;
}
else if (item5.equals("ardent censer"))
{
itemap = 60;
itemcdr = 10;
itemcost = 2300;
}
else if (item5.equals("athene's unholy grail"))
{
itemap= 30;
itemmr = 30;
itemcdr = 10;
itemcost = 2100;
}
else if (item5.equals("b.f.sword"))
{
itemad = 40;
itemcost = 1300;
}
else if (item5.equals("bami's cinder"))
{
itemhealth = 200;
itemcost = 900;
}
}
if(i == 5)
{
if(item6.equals("abyssal mask"))
{
itemhealth = 350;
itemmana = 300;
itemmr = 55;
itemcdr = 10;
itemcost = 2900;
}
else if (item6.equals("adaptive helm"))
{
itemhealth = 350;
itemmr = 55;
itemcdr = 10;
itemcost = 2800;
}
else if (item6.equals("aegis of the legion"))
{
itemarmor = 30;
itemmr = 30;
itemcost = 1100;
}
else if (item6.equals("aether wisp"))
{
itemap = 30;
itemcost = 850;
}
else if (item6.equals("amplifying tome"))
{
itemap = 20;
itemcost = 435;
}
else if (item6.equals("ancient coin"))
{
itemcdr = 5;
itemcost = 350;
}
else if (item6.equals("archangel's staff"))
{
itemap = 80;
itemmana = 250;
itemcost = 3100;
}
else if (item6.equals("ardent censer"))
{
itemap = 60;
itemcdr = 10;
itemcost = 2300;
}
else if (item6.equals("athene's unholy grail"))
{
itemap= 30;
itemmr = 30;
itemcdr = 10;
itemcost = 2100;
}
else if (item6.equals("b.f.sword"))
{
itemad = 40;
itemcost = 1300;
}
else if (item6.equals("bami's cinder"))
{
itemhealth = 200;
itemcost = 900;
}
}
System.out.println("Champion: " + champion);
System.out.println("Total health: " + totalhealth);
System.out.println("Total AD: " + totalad);
System.out.println("Total AP: " + totalap);
System.out.println("Total armor: " + totalarmor);
System.out.println("Total magic resist" + totalmr);
System.out.println("Total CDR: %" + totalcdr);
System.out.println("Total mana: " + totalmana);
System.out.println("Total Critical Strike Chance: " + totalcstr);
System.out.println("Total Life Steal: %" + totalls);
System.out.println("Total Attack Speed: " + totalatcksp);
System.out.println("Total Cost: " + totalcost + "g");
}
}
}
I am a highschool student on my first year of CS. This may have a simple answer that I am unaware of so I am open to all answers, even the most obvious.