| Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 11:00:32
|
heathfree
Newbie
Joined: 03/16/2006 06:45:12
Messages: 20
Offline
|
here is my homework I am not sure how to do the loop I think that I have the first part right but I do not know how to get the rest of it to work It is suppose to stop when -1 is enter She gives us two projects for each chapter and they are both different. she also gives us inclass but she did not use the while loops she used the for loops.
Can u help????
Instructions
Project 6
Write an application for the Garage Review Monthly Report, a magazine that surveys the cost of doing a particular job at various locations within the country.
PART1 Write an application called AutoGarage.java
1. In the main
a. It will prompt the article author to enter a job name
Example:
Enter the job name:
Oil change
b. It will declare appropriate variables to store his quiz grades
i. A double average //the average cost of that job
ii. A double total collected //total of all money from all jobs surveyed
iii. A double amount //cost of each job
iv. An int numItems // a counter of all jobs entered
v. A String name //the job name
c. It will create a Scanner object
2. write a while loop contolled on the amount entered being greater or equal to 0 (or not a -1)
3. It will then use a while loop to prompt the author to enter all job costs as surveyed separated by spaces, terminated with a -1
Example:
Enter all costs for the job: oil change separated by spaces:
19.95 14.55 20.99 -1
4. within the loop, add the amounts to the accumulating total, increment the numItems counter and read in the next amount using the scanner
5. when the loop ends (the terminal -1 was read), decrease the counter so that the -1 does not count as a job, calculate the average cost and output in a System.out.printf statement the name, number of jobs surveyed, total money collected and the average cost of that job. Do the same output in a JOptionPane – see sample below
Part 2
Modify the above code so that it prompts the article’s author to enter the maximum number of jobs in his survey using a JOptionPane
It will now need variables for a counter for the actual number of jobs and a maximum number of jobs
It will enclose the prompt for the job name and the while loop above in an outer loop controlled on the maximum number of jobs entered.
When the inner loop ends, increment the number of jobs counter and reset the average, total and numItem back to zero, then end the outer loop
Your output will look something like this:
It does not like my jpane
here is my code
import javax.swing.*;
import java.util.*;
import java.text.*;
public class AutoGarage
{
public static void main(String[]args)
{
Scanner s= new Scanner(System.in);
int numItems = 0;
String name = "";
double average = 0.0;
double totalcollected = 0.0;
double amount = 0.0;
while( numItems>=0)
{
System.out.println("enter all amounts collected separated by spaces,terminated with a -1");
numItems=s.nextInt();
average=s.nextDouble();
totalcollected=s.nextDouble();
amount=s.nextDouble();
totalcollected=numItems+amount;
average=totalcollected/numItems;
System.out.println();
System.out.println("Oil change");
System.out.printf("%-10s%10s%10s%10s%10s%n","NAME","jobs","Total Collected","average cost");
}
{
JOptionPane.showMessageDialog(null,"Oil change surveyed"+ numItems+"\n Total Jobs "+totalcollected+"\n Average sale ",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
This message was edited 1 time. Last update was at 03/23/2006 09:22:08
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 11:10:03
|
tfecw
Newbie
Joined: 09/19/2005 15:02:20
Messages: 144
Location: No. VA.
Offline
|
Please take some time an read the link that stdunbar referenced.
Step back from your assignment and take some time to think about what you are asking.
As the stdunbar's link said, be very descriptive with your specific problem.
"What is happening in your program" and "What do you think it should do" are 2 questions every new post should address.
So read the the thread stdunbar posted, and answer the 2 questions i've asked above and we'll give it another go.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 11:25:52
|
heathfree
Newbie
Joined: 03/16/2006 06:45:12
Messages: 20
Offline
|
I know what it is suppose to do but it is not doing it. I have been staring at it since 9 this morning. the loop is suppose to end when -1 is entered but I have no Idea how to code that I thought it may be But that is not working either but thanks for the help
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 11:32:25
|
tfecw
Newbie
Joined: 09/19/2005 15:02:20
Messages: 144
Location: No. VA.
Offline
|
What's happening when you type in -1?
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 12:01:54
|
heathfree
Newbie
Joined: 03/16/2006 06:45:12
Messages: 20
Offline
|
That did make it work but now I am not getting the the calutions I am suppose to get.
I am going to have to turn it in late
because I can not work on it anymore I have looked in the book and have search the web I have a funeral to go to tomorrow and a showing tonight I have put hours into this program and I thought that maybe some one could help me.
I am still searching as we speak for a while loop that will work like she wants it to.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 12:12:11
|
tfecw
Newbie
Joined: 09/19/2005 15:02:20
Messages: 144
Location: No. VA.
Offline
|
This is why you need to be specific. I was thinking you had a problem with your while loop, but now you are saying your calculations aren't working. I don't know what that means. What are you calculating, what are you getting vs what should you be getting. Use actual numbers.
Now as I read the last part of your post, you indicate that you are still having while loop troubles. I thought you said you figured it out.
...I thought that maybe some one could help me.
People can help you. I'm not a mind reader. Only you can tell me what you are having difficulty with. You can't just say "help me" and expect people to know what you are talking about.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 12:40:30
|
heathfree
Newbie
Joined: 03/16/2006 06:45:12
Messages: 20
Offline
|
I am no expert but most people can look at code and figure out what is wrong the code is there I added numItems = numItems -1;copy and paste in a program and u can see what is doing. I am a new programmer and will never do it again. the instructions r posted before. stop answering if u can not help
my code is below
import javax.swing.*;
import java.util.*;
import java.text.*;
public class AutoGarage
{
public static void main(String[]args)
{
Scanner s= new Scanner(System.in);
int numItems = 0;
String name = "";
double average = 0.0;
double totalcollected = 0.0;
double amount = 0.0;
while( numItems>=0)
{
numItems = numItems -1;
System.out.println("enter all amounts collected separated
by spaces,terminated with a -1");
numItems=s.nextInt();
average=s.nextDouble();
totalcollected=s.nextDouble();
amount=s.nextDouble();
totalcollected=numItems+amount;
average=totalcollected/numItems;
System.out.println();
System.out.println("Oil change");
System.out.printf("%-10s%10s%10s%10s%10s%n","NAME","jobs","Total Collected","average cost");
}
}
}
//{
//JOptionPane.showMessageDialog(null,"Oil change surveyed"+ numItems+"\n Total Jobs "+totalcollected+"\n Average sale ",
//JOptionPane.INFORMATION_MESSAGE);
//}
//}
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 13:10:24
|
stdunbar
Newbie
![[Avatar]](/images/avatar/a87ff679a2f3e71d9181a67b7542122c.png)
Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline
|
heathfree - I fully understand that you're frustrated but please don't take it out on us - we're unpaid volunteers that like to try to assist people.
Now, when I compiled your code the first thing I got was:
In looking at the code you have:
Notice that your format string is looking for 5 strings but you only supply 4. What did you mean to have as your 5th string?
|
Thanks for using the forums at hotjoe.com |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 19:41:56
|
heathfree
Newbie
Joined: 03/16/2006 06:45:12
Messages: 20
Offline
|
I am not trying to take anything out on anybody but I asked a question about the while Loop and how to get it to do what the assignment ask me to do, which was to end when I enter -1 I fix that then I was getting the error you were talking about. and I said that My calculations. are not working. I have really tried with this stupid java I just think this intro class is way to advance. Anyway I was working on that code for 7 hrs. by the time I ask for help I tried to do it on my own.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 19:54:54
|
heathfree
Newbie
Joined: 03/16/2006 06:45:12
Messages: 20
Offline
|
took out the fifth formatting num still getting error
enter all amounts collected separated by spaces,terminated with a -1
12.5 13.5 13.5 -1
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:819)
at java.util.Scanner.next(Scanner.java:1431)
at java.util.Scanner.nextInt(Scanner.java:2040)
at java.util.Scanner.nextInt(Scanner.java:2000)
at AutoGarage.main(AutoGarage.java:1
Press any key to continue . . .
do not know what to do with it?????
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/21/2006 21:54:12
|
stdunbar
Newbie
![[Avatar]](/images/avatar/a87ff679a2f3e71d9181a67b7542122c.png)
Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline
|
Your first scanner input is nextInt() - it needs an integer. I ran the code you posted in this thread with an integer first and then the doubles that you showed and, after fixing the printf it has at least a start.
|
Thanks for using the forums at hotjoe.com |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/22/2006 04:58:13
|
heathfree
Newbie
Joined: 03/16/2006 06:45:12
Messages: 20
Offline
|
This message was edited 1 time. Last update was at 03/22/2006 05:05:56
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/22/2006 08:04:32
|
stdunbar
Newbie
![[Avatar]](/images/avatar/a87ff679a2f3e71d9181a67b7542122c.png)
Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline
|
No, it isn't your code it is your input. You said you ran it with
The first number has to be an integer because that is the first scanner thing you're looking for.
|
Thanks for using the forums at hotjoe.com |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/22/2006 20:22:01
|
unknownterra
Newbie
![[Avatar]](/images/avatar/084b6fbb10729ed4da8c3d3f5a3ae7c9.jpg)
Joined: 03/22/2006 20:08:52
Messages: 10
Offline
|
Hi everyone,
I'm a little lost at the moment. My homework is to implement search types (breadth, depth, hill climbing, best first, lowest cost first, A* distance and A* time).
We have been given two files, places and distance. The Places file contains a list of places longitude and latitude. The following is an extract:
Adelong,3531,14806
Albury,3607,14692
Alstonvill,2885,15346
Armidale,3052,15167
Balranald,3464,14356
The Distances gives the origin, destination, distance in km and the road type. The road type is from 1 to 5 where each road type has a maxiumum speed allocated to it. Here is an extract:
Adelaide,Tailem Bend,99,1
Adelaide,Gawler,43,1
Adelaide,Port Wakefield,97,1
Albany,Bridgetown,276,5
Albany,Jerramungup,180,3
I have absolutley NO idea how to create the tree from this data to search through using the various algorithms. Do I read each line into an array, or vector, do I create a vector for each object separated by a comma, is it something completely different?
Before I can even begin doing the algorithms I need to know how to create the tree so I am very stuck.
Thanks,
ut
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 03/23/2006 09:11:53
|
stdunbar
Newbie
![[Avatar]](/images/avatar/a87ff679a2f3e71d9181a67b7542122c.png)
Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline
|
unknownterra - I split this thread up into a separate thread for you. In the future it is easier to create a new thread for your question so that the answers to your question won't get mixed up with the answers from the question that heathfree asked.
This message was edited 1 time. Last update was at 03/23/2006 09:39:55
|
Thanks for using the forums at hotjoe.com |
|
|
 |
|
|