Help me really quick since i don't understand ish in Computer science and the teacher isnt very good at explaining shit.
Help me find whats wrong with this?
I will probably update this thread with more help but help me fast please so i can get this hw done before walking dead.Code:public class retail { public static void main (String[] args); //Get the user's amount of purchase. System.out.print ("What was the amount of the purchase?"); amount = Keyboard.nextLine(); } }
Results 1 to 40 of 45
Thread: HW Help
- 11 Feb. 2013 12:18am #1
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 2.86
- Awards
HW Help
- 11 Feb. 2013 12:21am #2
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 2.34
- Awards
Help with these 2 also.
"Write a program that asks the user for the number of miles driven and the gallon of gas used. It should calculate the car's miles per gallon and display the result on the screen."
MPG=Miles driven/ Gallons of gas used.
"Write a program that asks the user to enter three test scores. The program should display each test score, as well as the average of the scores."
Rep will be given if i can.
- 11 Feb. 2013 12:22am #3
you need to import a scanner and make a scanner
- 11 Feb. 2013 12:25am #4
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 0.49
- Awards
- 11 Feb. 2013 12:27am #5
import java.util.*; //at the beginning <--- Because I'll always forget something if import individual utilities
Scanner in (<-your variable here) = new Scanner(System.in); <- making the scanner inside the loop
so...
import java.util.*;
public class retail {
public static void main (String[] args);
//Get the user's amount of purchase.
Scanner Keyboard = new Scanner(System.in);
System.out.print ("What was the amount of the purchase?");
amount = Keyboard.nextLine();
//also, I have no idea if you actually NEED to do nextLine. Because if you want an "amount", I'm guessing nextInt is what your teacher is looking for..
}
}
- 11 Feb. 2013 12:29am #6
Oh yeah, and if your teacher dislikes .util*;
import java.util.Scanner; <- is the import for only scanners
- 11 Feb. 2013 12:31am #7
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 0.76
- Awards
Its still saying its having problems with "System.out.print ("What was the amount of the purchase?");"
- 11 Feb. 2013 12:33am #8
I'm guessing if you understand scanners, you can do the 2nd real easily.
It's just taking two scanner inputs and dividing them.
- 11 Feb. 2013 12:34am #9
- 11 Feb. 2013 12:37am #10
- 11 Feb. 2013 12:37am #11
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 1.31
- Awards
- 11 Feb. 2013 12:42am #12
thanks xD
good luck :/
the memorization of some things in the very beginning was hard for me too
I was forgetting brackets , quotation marks, case-sensitive words, etc..
- 11 Feb. 2013 01:03am #13
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 0.76
- Awards
- 11 Feb. 2013 02:50am #14
System.out.println ("What was the amount of the purchase?");
// Signature
- 11 Feb. 2013 04:13am #15
So looking at your post, right away it doesn't seem like you have any kind of understanding of the basic concepts of the language at all.
If your teacher isn't very good and you prefer self-study I'd recommend Tutorials Point. They have a great introductory Java tutorial.
Code:import java.util.Scanner; public class Retail { public static void main(String[] args) { String amount; Scanner Keyboard = new Scanner(System.in); System.out.print("What was the amount of the purchase? "); amount = Keyboard.nextLine(); //System.out.println("The amount of the purchase was " + amount); } }
So, problems with the code.
Firstly, you didn't balance the braces for the main function. Every block needs to have an opening and closing brace. With a few exceptions such as if statements, but I won't go into that.
Secondly, you probably should have given the variable amount a type at the beginning of the program execution (main).
Although normally I would recommend giving it the value "double" or "float", we can't really do that here since the method you used to grab input from the user makes sure the user inputs a type of value known as a "string".
So instead we declare the storage container for the value the user wants to put in as a string.
Thirdly, you didn't tell Java what "Keyboard" was.
When you said Keyboard.nextLine you were basically invoking an operation if you will, that is an attribute of the object Keyboard. Because of this Java needs to know what Keyboard is.
Keyboard is going to be an object of the type "Scanner".
"Scanner" is not a "primitive data type" and thus not a core part of the language, therefore we need to import some files that tell us exactly what "Scanner" type object is. That's why I added the "import" section at the beginning of your code.
This is unnecessary.
Also, I hope your assignment doesn't require you to do any kind of mathematical operation with that variable amount. Otherwise you'll need to reformat your code.
As for the other pieces of code, seriously, read the tutorial. Or find some other user to do your homework for you.I don't get tired.
- 11 Feb. 2013 04:34am #16
I'm skipping to the bottom here and not reading any more posts after what was a chain of not the answer, so here:
public static void main (String[] args);
Should be a {, not a ;.
- 11 Feb. 2013 04:38am #17
- 11 Feb. 2013 04:40am #18
- 11 Feb. 2013 04:45am #19
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 1.33
- Awards
So much diff answers.
Yeah my teachr does suck because he tries to go through lessons so fast and get pissed when people asked questions knowing most of us are new to this.
Ill probably be looking through tuts later.
- 11 Feb. 2013 04:53am #20
- 11 Feb. 2013 04:59am #21
- 11 Feb. 2013 05:08am #22
*repeat
- 11 Feb. 2013 05:16am #23
Semantics. More appropriately I'll just say repeating, but for the record.
Regurgitate - "Repeat (information) without analyzing or comprehending it." - Merriam Webster
Doesn't seem like you read the posts that talked about the code error in question, therefore who's to say you didn't simply repeat the information without analyzing it let alone actually analyzing the entire first post which had more errors than one.Last edited by Isonyx; 11 Feb. 2013 at 07:12am.
I don't get tired.
- 11 Feb. 2013 05:23am #24
- 11 Feb. 2013 06:32am #25
- 11 Feb. 2013 07:11am #26
- 11 Feb. 2013 10:54am #27
CodingBat Java
really helps if you are trying to learn some java.
gives you some exercises !
- 11 Feb. 2013 04:12pm #28
- 12 Feb. 2013 04:21am #29
- 12 Feb. 2013 04:45am #30
- 12 Feb. 2013 02:04pm #31
- 12 Feb. 2013 03:14pm #32
- 12 Feb. 2013 08:37pm #33
Most pointless argument of the year. I nominate this one.
- 13 Feb. 2013 02:41am #34
- 13 Feb. 2013 02:57am #35
- Age
- 33
- Join Date
- Nov. 2009
- Location
- Everywhere. I have the internet
- Posts
- 4,100
- Reputation
- 440
- LCash
- 0.25
@Taz: Do you need to capitalize the "N" in "NextLine"?☜(* x *)☞FOOL ON COOL GENERATION
Originally Posted by C0FF1NCASE
- 13 Feb. 2013 06:42am #36
I wasn't trying to be a dick, I was trying to point out that you posted information in the topic that had already been contributed.
You were the one who went out of his way to criticize my choice of words.
Let alone you (for some reason) assuming your opinion was the singularly correct and only answer to a question that had already been answered. Quit your bitching.I don't get tired.
- 13 Feb. 2013 06:45am #37
I also said that I didn't read the above posts because there were too many replies to the OP to bother reading for such a simple answer that was requested. I checked the first five or six, and it wasn't mentioned. There were 10 more after that. So I stated in my first post why the content of my post might possibly be repeated information.
I was trying to point out that you posted information in the topic that had already been contributed.
You were the one who went out of his way to criticize my choice of words.
- 13 Feb. 2013 06:56am #38
Lol your information was provided in the third post.
Regurgitate is an insult? Never heard it used that way.
If you took it as an insult I apologize, I wasn't trying to be insulting.
I was wondering why you did what you did.
Either way your answer was incomplete.
You should have read more posts as a way of informing yourself.I don't get tired.
- 13 Feb. 2013 01:01pm #39
- Age
- 33
- Join Date
- Nov. 2009
- Location
- Everywhere. I have the internet
- Posts
- 4,100
- Reputation
- 440
- LCash
- 1.26
This is just spam now, guys come on.
This is what I"m talking about. If the JY is going to be a shithole for trolls and fights now, then keep it in the JY.
Otherwise, you're spamming a non-spam section.☜(* x *)☞FOOL ON COOL GENERATION
Originally Posted by C0FF1NCASE
- 13 Feb. 2013 03:36pm #40
That is literally the only meaning it has outside of its literal interpretation of vomiting. As per the definition already quoted, it means to repeat something without being able to critically analyze or understand it. It's an insult to the person's ability to think critically. You probably shouldn't use words you don't know what mean for this very reason. It has never meant anything other than 1) to vomit or 2) to insult someone's comprehension skills.
I was wondering why you did what you did.Originally Posted by my very first post