Click here to Skip to main content
15,890,336 members
Home / Discussions / Java
   

Java

 
GeneralRe: Code Help! Pin
Member 1072866719-Jul-15 9:29
Member 1072866719-Jul-15 9:29 
GeneralRe: Code Help! Pin
Wendelius19-Jul-15 9:34
mentorWendelius19-Jul-15 9:34 
GeneralRe: Code Help! Pin
Richard MacCutchan19-Jul-15 21:54
mveRichard MacCutchan19-Jul-15 21:54 
QuestionJava8 installer doesn't start w/o any messages Pin
moonwalker7206715-Jul-15 20:27
professionalmoonwalker7206715-Jul-15 20:27 
AnswerRe: Java8 installer doesn't start w/o any messages Pin
Richard MacCutchan15-Jul-15 21:40
mveRichard MacCutchan15-Jul-15 21:40 
QuestionJAVA Pin
Member 1183525613-Jul-15 20:24
Member 1183525613-Jul-15 20:24 
AnswerRe: JAVA Pin
Richard MacCutchan13-Jul-15 22:17
mveRichard MacCutchan13-Jul-15 22:17 
QuestionSales Tracking Assignment & Unfinished Code Pin
Member 1072866711-Jul-15 14:42
Member 1072866711-Jul-15 14:42 
I am still working on this myself, but I am kind of just needing a little reassurance that I am on the right track or a push in the right direction. This is all really new to me, and I'm honestly getting a little overwhelmed. Thank you!

You must create a sales tracking program named SalesTracking.java. This program will use arrays to store and process monthly sales as well as compute average yearly sales, total sales for the year, and which month had the highest sales and which month had the lowest sales. You should use parallel arrays. Your first array (monthArray) should be initialized with all of the months. This array should have 12 locations of course. Your other array should be named monthlySales. Like your monthArray, this array should be 12 locations that store the amount of sales for each month.

The program should prompt the user for the sales for each month starting with January. The arrays (monthlySales and monthArray) should be created in main and passed to the methods as needed. Your program should have methods that do the following.

getSales(monthArray, monthlySales): This method receives the monthArray and monthlySales arrays as arguments. It prompts the users for the sale for each month. This amount should be stored and returned into the corresponding location in the monthlySales array. For example, January sales should be stored in the first location, February sales should be stored in the second location, and so forth.

computeTotalSales(monthlySales): This method receives the monthly sales array as an argument and returns the total sales of the year.

computeAverageSales(monthlySales): This method receives the monthly sales array as an argument and returns the average sales for the year.

computeHighestMonth(monthlySales): This method receives the monthly sales array as an argument. This method will search and compare the values of the monthly sales array for the highest value. The method will return the index(or location in the array) of the month with the highest value.

computeLowestMonth(monthlySales): This method receives the monthly sales array as an argument. This method will search and compare the values of the monthly sales array for the lowest value. The method will return the index (or location in the array) of the month with the lowest value.

displaySaleInfo(totalSales, averageSales, highestMonth, highestSales, lowestMonth, lowestSales): This method will receive the total yearly sales, average monthly sale, the month with the highest sales, as well as the sales for that month and the month with the lowest sales. This method will display all of the data it received as arguments.

All methods should be STATIC therefore no object will need to be instantiated to call them. All methods must be called from the main method. Sales amounts should be rounded to two decimal places.
Java
public class SalesTracking
{
    public static void main(String[] args)
    {
        //This introduces the scanner to simplify receiving user input.
        Scanner input = new Scanner(System.in);

<pre>
    //These statements declare the variables.
            double totalSales = 0;
            double averageSales = 0;
            double highestMonth = 0;
            double lowestMonth = 0;
            double highestSales = 0;
            double lowestSales = 0;

            total = computeTotalSales(monthlySales);
            average = computeAverageSales(monthlySales);
            highest = computeHighestMonth(monthlySales);
            lowest = computeLowestMonth(monthlySales);

    //This is the array that stores the months of the year.
    String[] monthArray = {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", 
                           "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
    for (String month : monthArray); 
    {
        System.out.println(Arrays.toString(monthArray));
    }

    //This is the array that prompts for, stores, and displays the monthly sales.
    double[] monthlySales = new double[12];
    for (int index = 0; index < monthlySales.length; index++)
    {
        System.out.print("Enter the monthly sales: ");
        monthlySales[index] = Double.parseDouble(input.nextLine());
    }
        System.out.println("The monthly sales are: ");
        for (int index = 0; index < monthlySales.length; index++)
        { 
            System.out.println(monthlySales[index]);
        }
}//This bracket ends the main.

//This method receives the monthArray and monthlySales array and prompts the user for 
//each month's sales.
public static void getSales (String monthArray, double monthlySales)
{   
}

//This method receives the monthlySales array and returns the total yearly sales.
public static double computeTotalSales(double[] monthlySales)
{
double total = 0.0;
for(double index = 0; index < monthlySales.length; index++)
{
total += monthlySales[(int) index];
}
return total;
}
//This method receives the monthlySales array and returns the average yearly sales.
public static double computeAverageSales (double[] monthlySales)
{
double averageSales = 0;
double totalSales = 0;
averageSales = totalSales/monthlySales.length;
return averageSales;
}

//This method receives the monthlySales array and returns the index (or location)
//of the month with the highest value.
public static double computeHighestMonth (double[] monthlySales)
{
double highestMonth = monthlySales[0];
for (double index = 1; index < monthlySales.length; index++)
{if(monthlySales[(int) index] > highestMonth)
{
highestMonth = monthlySales[(int) index];
}
}
return highestMonth;
}

//This method receives the monthlySales array and returns the index (or location)
//of the month with the lowest value.
public static double computeLowestMonth (double[] monthlySales)
{
double lowestMonth = monthlySales[0];
for (double index = 1; index < monthlySales.length; index++)
{if(monthlySales[(int) index] < lowestMonth)
{
lowestMonth = monthlySales[(int) index];
}
}
return lowestMonth;
}

//The method receives the total yearly sales, average monthly sales, the month
//with the highest sale and its sales, and the month with the lowest sales and
//its sales and displays all of the data.
public static double displaySaleInfo (double totalSales, double averageSales,
double highestMonth, double highestSales, double lowestMonth, double
lowestSales)
{
System.out.print("The total sales are: " + totalSales);
System.out.print("The average sales are: " + averageSales);
System.out.print("The month with the highest sales is: " + highestMonth);
System.out.print("The highest sales for that month is: " + highestSales);
System.out.print("The month with the lowest sales is: " + lowestMonth);
System.out.print("The lowest sales for that month is: " + lowestSales);
return lowestSales;
}
//This bracket ends the class.


modified 12-Jul-15 3:54am.

QuestionRe: Sales Tracking Assignment & Unfinished Code Pin
Richard MacCutchan11-Jul-15 21:56
mveRichard MacCutchan11-Jul-15 21:56 
QuestionThe Use Of Webcam To Capture Image And Video Streaming Pin
goddynk8-Jul-15 1:28
goddynk8-Jul-15 1:28 
Questioni want to solve this probelem. pls help me. Pin
Member 118168846-Jul-15 3:56
Member 118168846-Jul-15 3:56 
GeneralRe: i want to solve this probelem. pls help me. Pin
PIEBALDconsult6-Jul-15 4:32
mvePIEBALDconsult6-Jul-15 4:32 
AnswerRe: i want to solve this probelem. pls help me. Pin
Richard MacCutchan6-Jul-15 5:30
mveRichard MacCutchan6-Jul-15 5:30 
AnswerRe: i want to solve this probelem. pls help me. Pin
Member 117346789-Jul-15 1:37
Member 117346789-Jul-15 1:37 
QuestionJava course Pin
Member 118100102-Jul-15 16:54
Member 118100102-Jul-15 16:54 
QuestionRe: Java course Pin
Richard MacCutchan2-Jul-15 21:19
mveRichard MacCutchan2-Jul-15 21:19 
AnswerRe: Java course Pin
vicsepu20036-Jul-15 9:58
vicsepu20036-Jul-15 9:58 
QuestionMessage Closed Pin
1-Jul-15 15:02
CptDanko1-Jul-15 15:02 
AnswerRe: Making iOS apps like making a Java web app Pin
Richard MacCutchan1-Jul-15 21:21
mveRichard MacCutchan1-Jul-15 21:21 
GeneralRe: Making iOS apps like making a Java web app Pin
CptDanko1-Jul-15 23:29
CptDanko1-Jul-15 23:29 
QuestionJava Pin
LysiasTJ30-Jun-15 23:33
professionalLysiasTJ30-Jun-15 23:33 
AnswerRe: Java Pin
Richard MacCutchan1-Jul-15 0:25
mveRichard MacCutchan1-Jul-15 0:25 
QuestionJquery slideshow Pin
vikkismarty29-Jun-15 4:56
vikkismarty29-Jun-15 4:56 
AnswerRe: Jquery slideshow Pin
Richard MacCutchan29-Jun-15 5:08
mveRichard MacCutchan29-Jun-15 5:08 
Questionjava programming Pin
vikkismarty29-Jun-15 1:15
vikkismarty29-Jun-15 1:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.