+ 1

Can anyone help?

My courseWork is to add names to an array, search and print to a Java program language. The teacher gave us a sample, but the further I go into the code, the more errors happen ... The sample isn't what I see on YouTube or Google and the examples from Google don't match.

27th May 2020, 2:14 AM
PresidentJava
PresidentJava - avatar
4 odpowiedzi
0
Thank you. So far this is what I have done. I'm not sure if the arrays is correct using these codes too. When I check google or YouTube codes, they don't really match, because the explanations already have data in the arrays, meanwhile in my code I have to let the user insert the data
27th May 2020, 5:29 PM
PresidentJava
PresidentJava - avatar
0
import java.util.*; public class CourseWork{ static Scanner sc = new Scanner(System.in); static int noOfAnimals = 0; static String [] listOfNames = new String[10]; static int [] ageOfAnimal = new int[10]; static int [] priceOfAnimal = new int[10]; public static void main(String [] args){ int choice = 0; while(choice != 8){ menu(); choice = Integer.parseInt(sc.nextLine()); if(choice == 1){ addAge(); } if(choice == 2){ searchAge(); } if(choice == 3){ } if(choice == 4){ System.out.println("Update animal"); } if(choice == 5){ System.out.println("Sort data"); } if(choice == 6){ System.out.println("Save data to file"); } if(choice == 7){
27th May 2020, 5:30 PM
PresidentJava
PresidentJava - avatar
0
} if(choice == 8){ System.out.println("quit"); System.out.println("Thank you, goodbye"); } } } public static void menu(){ System.out.println("Choose an option between 1 and 8"); System.out.println("1, Add animal's name,age and price"); System.out.println("2, Search for animal, age or price"); System.out.println("3, Print animals"); System.out.println("4, Update data"); System.out.println("5, Sort data"); System.out.println("6, Save data to file"); System.out.println("7, Retieve data from file"); System.out.println("8, Quit"); } public static void addAnimal(){ System.out.println(""); System.out.println("Add the animals name"); String name = sc.nextLine(); listOfNames[noOfAnimals] = name; noOfAnimals++; } public static void addAge(){ System.out.println("");
27th May 2020, 5:32 PM
PresidentJava
PresidentJava - avatar
0
System.out.println(""); System.out.println("Add the animals age"); int animalAge = Integer.parseInt(sc.nextLine()); ageOfAnimal[noOfAnimals] = animalAge; noOfAnimals++; } public static void addPrice(){ System.out.println(""); System.out.println("Add the animals price"); int animalPrice = Integer.parseInt(sc.nextLine()); priceOfAnimal[noOfAnimals] = animalPrice; noOfAnimals++; } public static void searchAge(){ } }
27th May 2020, 5:33 PM
PresidentJava
PresidentJava - avatar