Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I\'m a complete newbie and I don\'t know exactly what I\'m doing. I need

ID: 3540870 • Letter: H

Question

Hello,


I'm a complete newbie and I don't know exactly what I'm doing. I need help solving this from the book Java Programming Joyce Farrell.



Here it is.

Create a class that holds the service description, price, and the number of minutes it takes to perform the service. Include a constructor that requires arguments for all three data fields and three get methods that each returned one of the data field's values. Save the class as Service.java b. Write an application name SalonReport that contains an array to hold six Service objects, and fill it with the data from Table 9-6. Include methods to sort the array in ascending order by each of the data fields. Prompt the user for the preferred sort order, and display the list of services in the requested order. Save the program as SalonReport.java Enhance the program by displaying a menu that asks the user how they want to sort the services menu. 1) Sort by Service Description, 2) Sort by Price, 3) Sort by Time (Minutes), or 0) to Exit. Add a do...whUeQ loop that keeps prompting the user for the next preferred sort order until the user finally chooses "0" to exit. Add comments.

Explanation / Answer

please rate - thanks

any questions ask--I will answer


partial run


class Service
{private String description;
private double price;
private int minutes;
public Service()
{description="";
price=0;
minutes=0;
}

public Service(String d,double p,int m)
{description=d;
price=p;
minutes=m;
}
public String getDescription()
{return description;
}
public double getPrice()
{return price;
}
public int getMinutes()
{return minutes;
}
}


-------------------------------------------------------------

import java.util.*;
class SalonReport
{
public static void main(String[] args)
{Service s[]={new Service("Cut",8.00,15),new Service("Shampoo",4.00,10),
            new Service("Maincure",18.00,30),new Service("Style",48.00,55),
                new Service("Permanent",18.00,35),new Service("Trim",6.00,5)};
Scanner in=new Scanner(System.in);
int choice;
do
{choice=menu(in);
switch(choice)
{case 1: sortDescription(s);
         break;
case 2: sortPrice(s);
         break;
case 3: sortTime(s);
case 0: break;
default: System.out.println("Invalid choice");
}
}while(choice!=0);
}

public static int menu(Scanner in)
{System.out.println("How do you want to sort?");
System.out.println("1) Sort by Service Description");
System.out.println("2) Sort by Price");
System.out.println("3) Sort by Time (Minutes)");
System.out.println("0)Exit");
System.out.print("Enter choice: ");
return in.nextInt();
}
public static void print(Service[] s)
{System.out.println("Service Description   Price($)   Time(Minutes)");
for(int i=0;i<s.length;i++)
    System.out.printf("%-23s%8.2f%10d ",s[i].getDescription(),s[i].getPrice(),s[i].getMinutes());
System.out.println();
}
public static void sortPrice(Service[] s)
{int i,j;
for(i=0;i<s.length-1;i++)
    for(j=i+1;j<s.length;j++)
         if(s[i].getPrice()>s[j].getPrice())
               swap(s,i,j);
print(s);
}
public static void sortDescription(Service[] s)
{int i,j;
for(i=0;i<s.length-1;i++)
    for(j=i+1;j<s.length;j++)
         if(s[i].getDescription().compareTo(s[j].getDescription())>0)
               swap(s,i,j);
print(s);
}
public static void sortTime(Service[] s)
{int i,j;
for(i=0;i<s.length-1;i++)
    for(j=i+1;j<s.length;j++)
         if(s[i].getMinutes()>s[j].getMinutes())
               swap(s,i,j);
print(s);

}
public static void swap(Service[] s,int i,int j)
{Service temp=new Service();
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}


   



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote