473,394 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to set the total for each category from each room in my code?

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. public class flooring
  3. { public static void main(String[]args)
  4.      {Scanner flo=new Scanner (System.in);
  5.       int rooms=getroomnumber(flo,"How many rooms you are flooring: ");
  6.       for(int i=1;i<=rooms;i++)
  7.           { System.out.println("Room number: " + i + "\n"); 
  8.      int lenght=getnumbers(flo,"Enter lenght of room(ft):" );
  9.       int width=getnumbers(flo,"Enter width of room(ft):" );
  10.       int costfloor=getnumbers(flo,"Enter cost of flooring($ per square foot):");  
  11.       int area=getarea(lenght, width);
  12.       double hourlabor=gethourlabor(area);
  13.       int carton=getcarton(area);
  14.       double costflooring=getcostflooring(costfloor, carton);
  15.       double laborcost= getlaborcost( hourlabor);
  16.       double costsupplies=getcostsupplies(laborcost);
  17.       draw();
  18.       double totalcost=gettotal(laborcost, costsupplies, costflooring);
  19.         for (double j=1;j<=rooms;j++) 
  20.          {double totalhour=+hourlabor;
  21.  
  22.  
  23.       System.out.println("Total hours of labor: " + totalhour );
  24.             System.out.println("Total number of cartons: ");
  25.             System.out.println("Total cost of flooring: $");
  26.             System.out.println("Total cost of supplies: $");
  27.             System.out.println("Total labor cost: $");
  28.             System.out.println("Final cost: $");}
  29.  
  30.  
  31.  
  32.     }}
  33.    public static int getroomnumber(Scanner flo, String s )
  34.     {int rooms;
  35.     System.out.print(s);
  36.     rooms=flo.nextInt();
  37.     System.out.println();
  38.          return rooms;
  39.      }
  40.  
  41.     public static int getarea( int lenght, int width)
  42.      { int area= lenght *width;
  43.       return area;
  44.       }
  45.      public static double gethourlabor(int area)
  46.   {  
  47.      double hourlabor=(area/200)*3;
  48.      System.out.println("Hours of labor required: " + hourlabor);
  49.     return hourlabor;  
  50.    }
  51.  
  52.    public static int getcarton(int area) 
  53.   {  int carton=(int)(Math.ceil((double)area/12));
  54.    System.out.println("Cartons of flooring needed: " + carton);
  55.    return carton;
  56.    }
  57.   public static double getcostflooring(int costfloor,int carton)
  58.    {
  59.    double costflooring=(carton*12)*costfloor;
  60.    System.out.println("Cost of the flooring: $" + costflooring);
  61.    return costflooring;
  62.    }
  63.    public static double getlaborcost( double hourlabor)
  64.    {double laborcost=hourlabor*40;
  65.    System.out.println("Labor cost: $"  + laborcost);
  66.    return laborcost;
  67.    }
  68.  
  69.    public static double getcostsupplies( double laborcost)
  70.     {double costsupplies = laborcost/5;
  71.    System.out.println("Cost of supplies: $" + costsupplies); 
  72.    return costsupplies;
  73.    }
  74.    public static void draw() 
  75.     {for(int i=1;i<=19;i++)
  76.       System.out.print("-");
  77.       System.out.println();}
  78.  
  79.   public static double gettotal(double laborcost, double costsupplies , double costflooring)
  80.    {double totalcost=laborcost + costsupplies + costflooring;
  81.     System.out.println("Total cost: $" + totalcost);
  82.     System.out.println(); 
  83.     return totalcost;
  84.   }
  85.  
  86.   public static int getnumbers( Scanner flo, String prompt)
  87.   { int numbers;
  88.    System.out.print(prompt);
  89.    numbers=flo.nextInt(); 
  90.    return numbers;
  91.    }
  92. }   
  93.  
  94.  
May 28 '17 #1
1 1198
chaarmann
785 Expert 512MB
loop through all rooms.
Make a hashmap with key = category and value = grandTotal (which is initially 0) and add the total of the current room there while looping.
That means: At the beginning, this hashmap is empty. If the category of the current room does not exist in the map, add it to the map. Then always get the existing entry and add the current total to the grandTotal value there.

At the end, loop through all all keys (categories) of the hashmap and print out the grandTotal there.
May 29 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rich Protzel | last post by:
Hello, So my table contains say 100,000 records, and I need to group the categories in fld1 by the highest count of subcategories. Say fld1 contains categories A, B, C, D, E. All of these...
3
by: Tjerk Wolterink | last post by:
Hello, i've an xml doc like this: <doc> <item>a</item> <item>b</item> <item>c</item> <item>d</item> <item>e</item> <item>f</item> <item>g</item>
7
by: Barkster | last post by:
I'm trying to list my categories and how many items are in each category. I'm not much on sub queries. How can I combine these two items. I'd like to display the category and the corresponding...
7
by: FrankEBailey | last post by:
I'm not sure if this is a completely dumb question, but please humor me :) I have a table of records, called Records, each of which has a Category_ID that places it in a specific category; the...
1
by: vishalgupta | last post by:
in the following code i am trying to display the each category name in the table as a link to cat.html <html> <head> </head> <body> <?php $str1="<a href=cat.html>"; $str2="<//a>";...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a webform with several entry boxes and the user enters numbers in each box. I keep a running total (just adds all of the entries together) but am posting back to the server to do this. ...
11
by: tsokid | last post by:
I have many rows (around 3000) with some columns. Each of them are under a row with only the first (A) column filled. See below Category A 1983 15648 156156 416 151 021 987464 156156 416 151 021...
1
by: rosemary slack | last post by:
I am trying to show a category, for example shoes and then show all the shoes in that category and then show the next category and all the products in that category and so on. I am able to show all...
9
by: Rocks | last post by:
Hi there, I have a table called categories that contains: id, name, subcategory_id, parent_id. And another table classifieds that contains: classified_id, title, category_id. I am trying to pull...
1
by: virtualweb | last post by:
Hello I'm doing a basic Item Catalog based on Flat File databases. My Category Database (Categories_List.txt) has Categories in this manner: OILS CANNED FOODS LIQUORS WINES VEGETABLES
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.