Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Chapter 8, you created a Salesperson class with fields for an ID number and sales values. Now, create an application that allows a user

In Chapter 8, you created a Salesperson class with fields for an ID number and sales values. Now, create an application that allows a user to enter values for an array of seven Salesperson objects. Offer the user the choice of displaying the objects in order by either ID number of sales value. Save the application as SalespersonSort.java

I keep getting ERRORS...PLEASE HELP..........CODE BELOW............................

import java.util.Scanner; public class SalespersonSort { public static void main(String[]args) { final int size=7; Salesperson[] Salespersons=new Salesperson[size]; Scanner scanner=new Scanner(System.in); Salespersons[0]=new Salesperson(100,5000); Salespersons[1]=new Salesperson(101,7000); Salespersons[2]=new Salesperson(102,6000); Salespersons[3]=new Salesperson(103,10000); Salespersons[4]=new Salesperson(105,2000); Salespersons[5]=new Salesperson(106,900); Salespersons[6]=new Salesperson(110,8000); print(Salespersons); System.out.println("--->Menu<---"); System.out.println("1.Sort by ID"); System.out.println("2.Sort by Sales"); System.out.println("Enter choice (1 or 2 ):"); int choice=scanner.nextlnt(); switch(choice) { case 1: sortByID(Salespersons); print(Salesperson2); break; case 2: sortBySales(Salespersons); print(Salespersons); break; default: System.out.println("Invalid Choice"); } } private static void sortByID (Salesperson[] Salespersons) { Salesperson tempPerson; for(int i= 0; i < Salespersons.length-1; i++) { for (int j = 0; < Salespersons.length-1; j++) { if (Salespersons[j].getID()>Salespersons[j+1].getID()) { temPerson=Salespersons[j]; Salesperson[j]=Salesperson[j+1]; } } } } private static void sortBySales (Salesperson[] Salespersons) { Salesperson tempPerson; for (int i = 0; iSalespersons[j+1].getSales()) { temPerson=Salespersons[j]; Salespersons[j]=Salespersons[j+1]; Salespersons[j+1]=Tempperson; } } } } private static void print(Salesperson[] Salespersons) { System.out.printf("%-15s%-10s ","ID","Sales"); System.out.println("------------------"); for (int index = 0; index < Salespersons.length; index++) { System.out.printf("%-10d%10.2f ", Salespersons[index].getID(), Salespersons[index].getSales()); } }

xxxxxxxxxxxxx MY SALESPERSON CODE BELOWxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

public class Salesperson { int ID; double annual_sales; public Salesperson(int id, double Sales) { ID = id; annual_sales = Sales; } public int getID() { return ID; } public void setID(int id) { ID = id; } public double getSalesamount() { return annual_sales; } public void setSalesamount(double Sales) { annual_sales = Sales; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions