I have created two arrays to enter the name and store the sale I try to add the indexes of each one together So that the name array from index 1 will then bring the value of index 1 of array of sales. I am trying to solve this sale array and return the maximum sale and the person coming into that sale. All values are input by the user with the size of the array.
import java.util.Scanner; Import java.util.Arrays; Public Category EmpArray {Public Static Ent Worker (Scanner) = New Scanner (System.in); Int numemp; System.out.println ("How many employees compare: \ n"); Numemp = input.nextInt (); String name [] = New string [numemp]; Int annsales [] = new int [numemp]; Int Maxless; For (int i = 0; i & lt; name.length; i ++) {System.out.println ("Enter your name: \ n"); Letter employineame = input.next (); Name [i] = employment symbol; Println ("\ n"); } For (int jm = 0; j & lt; annsales.length; j ++) {System.out.println ("Enter in your annual sales: \ n"); Int Number of employees = input.nextInt (); Anselace [J] = Employees; Println ("\ n"); } System.out.println ("employee's name:" + Arrays.toString (name)); System.out.println ("Total Sales:" + Arrays.toString (annsales)); Arrays.sort (annsales); // See To begin page 456 with Java and page 460 of the same book, p.464 System.out.println ("Top salary: $" + annsales [annsales.length-1]); Maxnasless = Anselace [Anselace. Lanti-1]; Returns max; }} What I am doing wrong for two weeks on this
You should create a class to store dates instead of using two different arrays.
Public Sector Staff {Private Equity Sales; The name of the private string; Public employee (string name, int sale) {this.name = name; This.sales = sale; } Public string getName () {this.name; } Public int getSales () {Return this sale. }} Now when you read from your scanner and pass them to the Employee Constructor, store the name and sale as a local variable. After this you can see a employee array [] or ArrayList & lt; Employee & gt; and Employee.getSales () similarly:
Import java.util.Scanner; Import java.util.Arrays; Public class EmpArray {public static zero chief (string [] args) {employee (); } Public Static Ent Operators () {Scanner input = New scanner (System.in); Int numEmp; System.out.println ("How many employees compare:"); NumEmp = input.nextInt (); Input.nextLine (); Employee [] employee = new employee [number ampe]; {System.out.print ("Enter your name:") for (Int i = 0; I & lt; numEmp; i ++); String employee name = input.nextLine (); Println (); System.out.print ("Enter in your annual sales:"); Intel Employees = Input Xx (); Input.nextLine (); Println (); // Employee employee employee = creates an employee object based on the manufacturer defined in new employee (employee name, employees); Employee [i] = employee; } // First MaxSeller employee employee starts MaxSeller for staff [0]; For (Int i = 0; I & lt; employee; length; i ++) {// We use Gifters built into employee systems. Out.println ("employee's name:" + employee [i] .getName ()); System.out.println ("Total Sales:" + Employee [i] .getSales ()); Println (); // Check if employees [i] are sold more than MaxSeller (Maxelseller.Gatesless) & employee employee [i] .getSales ()) {maxSeller = employee [i]; }} System.out.println (); System.out.println ("Top Sellers:" + maxseller.getName ()); System.out.println ("Top Sales:" + maxseller.getSales ()); Return maxseller.getSales (); }}
No comments:
Post a Comment