Java Need To Enter 5 Grades And Can Only Enter 1 For Grade Conversion
Sep 13, 2014
How to improve my code. I finally was able to create a program that gives you the corresponding letter grade, when you enter in a numeric grade without using an array. The only issue left is that I have to be able to enter 5 grades at a time, and it give me the letter grade for all 5. I have the programming working, but only am able to enter 1 at a time. I am not sure what kind of loop or if I am supposed to use a loop.
public static void main(String[] args){
{
int grade = 0;
Scanner input = new Scanner(System.in);
System.out.println("Enter : ");
grade = input.nextInt();
if (grade >= 90)
[Code] .....
View Replies
ADVERTISEMENT
Sep 2, 2014
I'm using Jgrasp and my prompt is asking me to write a program where the program prompts the user to enter 4 grades between 0 and 100. And you have to display the grades, and the program has to calculate the minimum grade, the maximum grade and the average.I'm just having problems with the max?
// Import Java Scanner.
import java.util.Scanner;
// Name Class.
public class Practice_4_1
[code]...
View Replies
View Related
Apr 30, 2015
package question.pkg3;
import java.util.Scanner;
public class Question3 {
public static void main(String[] args) {
// TODO code application logic here
Scanner Luka=new Scanner(System.in);
double sum=0;double count=0;
int[] a=new int[10];
[code]....
I'm required to write a program that allows the user to enter up to 10 integer grades into an array. Stop the loop by typing in ‐1. Your main method should call an Average method that returns the average of the grades.I There's something wrong with my program , the count always stays 0 and the sum is always 1 less than the actual sum.Sample input and output :
Enter grade 1: 8
Enter grade 2: 9
Enter grade 3: 10
Enter grade 4: 5
Enter grade 5: 8
Enter grade 6: 9
Enter grade 7: -1
output
Average grade is 8.1666666667On line 13 I had count=count+1 ;
View Replies
View Related
Feb 2, 2015
Ok so I have my program working for the most part. In this program I am supposed to take input from the user until they enter a negative number and that works, the problem is that it doesn't work if I enter a negative number on the first prompt. For example if I enter a 100 it would prompt me again and if I enter a negative number it would quit and give me the average, but if I enter a negative number the first time I am prompted the program just gives me an error. How do I fix that?
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
public class Application {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
List<Integer> grades;
[Code] ....
View Replies
View Related
Oct 9, 2014
I am trying to write a code that allows you to input 2 lists and it tells you if they are identical or not. However, when I enter my fist list I can only enter two values and then it asks for the next list. How would I fix this to allow me to enter more than two values?
Also, If the second list is different it has me enter more values that list one.
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Enter values for list1
System.out.print("Enter list1: ");
int size1 = input.nextInt();
int[] list1 = new int[size1];
for (int i = 0; i < list1.length; i++)
list1[i] = input.nextInt();
// Enter values for list2
System.out.print("Enter list 2: ");
[code]...
My output looks like this:
Enter list1: 1
2
Enter list 2: 2
3
2
Two lists are not identical
View Replies
View Related
Jan 26, 2014
My program is supposed to let me enter the following info for 3 employees: name, number of hours worked this week, and hourly pay rate. It lets me enter the name for the first employee, but for the second and third, it skips over the name and forces me to enter the number of hours worked and pay rate without a name. I have the code and the output posted below. First the program code:
Java Code:
import java.util.Scanner;
public class SalaryCalc {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name;
double hours;
double rate;
double grossPay = 0;
double overtime;
[code]...
Enter hours worked this week: mh_sh_highlight_all('java'); Notice I can only enter the name for the first employee (Bigfoot). If I wanted to enter "Nessie" for my second employee's name, it skips over the name prompt and prompts me for the hours worked instead.
View Replies
View Related
Oct 7, 2014
I'm currently taking a Java Programming module in college, the program we are using is jGrasp and I'm currently stuck on one aspect of the language.
I did VB last year and I enjoyed it and got good grades so I'm comfortable with Java in terms of compiling the code correctly and getting it to run with no errors.
But for a project we got yesterday, the user must be able to enter data (e.g. an answer) into jGrasp without using a GUI. This is the case because we won't be dealing with GUIs until next semester.
I'm able to handle the rest of the project, but the part which I can't figure out is how the user can interact with jGrasp without the aid of a GUI.
View Replies
View Related
Jun 21, 2014
I want to enter the triangle data in the method and every time I try to compile the program I get the error message--cannot find symbol.
import java.io.*;
import java.util.*;
public class trianglemethod {
public static void main(String [] args) {
Scanner kbreader = new Scanner (System.in);
[Code] .....
View Replies
View Related
Mar 29, 2014
I'm working with a project there ill need to enter some values for an Object and for this i'm using JTextField. However some of the variables are of the types double, int and bool. Is there a different method of reading thees types?
for example:
double playTime = this.playTime.getText();
This won't work because playTime is of type double and .getText(); takes a String.
How will i handle this? Id rather not convert from String to Double if its possible.
View Replies
View Related
Feb 15, 2015
I am suppose to design a problem the prompts the user to enter a String. Based on the input from the user, have the program prompt with a full description of the playing card entered. Below is a table of the notation and meaning:
Notation Meaning
A Ace
2...10 Card Values
J Jack
Q Queen
K King
D Diamonds
H Hearts
S Spades
C Clubs
Use the .charAt(...) to extract each character from the user's input and build a switch statement to determine the full description.
import java.util.Scanner;
public class PlayingCardIdentifier {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a card notation: ");
String s = input.nextLine();
[code]...
View Replies
View Related
Apr 4, 2015
I have a class called "HelloController" and it extends SimpleFormController. I have the following method inside of HelloController.java:
protected Map referenceData(HttpServletRequest request) throws Exception {
Map<String,String> language = new dHashMap<String,String>();
language.put("Spanish", "Buenos Dias");
language.put("French", "Bonjour");
return language;
}
How would I create a JSP file that would accept a language as its input and return a greeting in that language? For example, if the user enters "Spanish", then the user should see "Buenos Dias." If the user enters "French", then the user should a see "Bonjour".
View Replies
View Related
Oct 5, 2014
I am learning Java on my own, and I am creating little programs to do so.The program below asks the user to input text and hit enter. When user does that, it asks if that is correct. If the user enters "y," the program ends. That's good.If the users enters "n," the strGrategul is set to empty which triggers the while statement to start over again. That's good. However, when the program asks the user to "Tell me one thing you are grateful for..." it doesn't wait for user input. Instead it skips to "You said ''? Enter 'y' or 'n'" It thinks the user enter an empty line.
public static void main(String[] args) {
String strGrateful = "";
String strGoal = "";
String strContinue = "";
Scanner scn = new Scanner(System.in);
[code]....
View Replies
View Related
Nov 8, 2014
How can I get enter(return) as empty input from user?!
scanner.next will wait until I input a string ...
But I want it when I hit return sets the variable to empty string ...
View Replies
View Related
Apr 21, 2014
I'm trying to write a program where the user has the option to enter either an int or double but whatever input I enter just gets cast to a double. Do I even have the right Idea by using if else statements?
import java.util.*;
public class VS
{
public static void main(String[] args) {
Scanner Input = new Scanner(System.in);
System.out.println("Please enter a number");
if (Input.hasNextDouble()) {
[Code] ....
View Replies
View Related
Feb 28, 2015
The goal of this section of my assignment is to ask the user for a password. The password entered has to match the password I set in the code. If it is correct the next dialog box will pop up.
my password is set to:
String enterpwd = "";
String correctPassword = "Setpassword";
I am asked to use JOption, I completed as follows:
enterpwd = JOptionPane.showInputDialog(""............JOptionPane.QUESTION_MESSAGE);
then I use IF statements
if (enterpwd == correctPassword)
xyz = JOption .......();
I am getting an error "java.lang.NumberFormatException: For input string: """
View Replies
View Related
Apr 4, 2015
double CashInsert = Double.parseDouble(CashAmounttxt.getText());
System.out.println("Cash Received: " + "£" + CashInsert);
if (CashInsert<=0 &&(CashInsert <TotalPrice)){
ChangeLeft = CashInsert - TotalPrice;
System.out.println("Total: £" + TotalPrice);
System.out.println("Change Due: " + "£" + ChangeLeft);}
else {
System.out.println("Insuffient funds, please enter £"+ TotalPrice +" or More");}
}
#################################################
Cash Received: £-1.0
Total: £4.85
Change Due: £-5.85
It allows me to enter -1 I've already coded it so the person cannot enter less but -1 works.
View Replies
View Related
Sep 3, 2014
With the switch of the JVM version in our project, it turned out that the default behavior of Button has changed from JavaFX 2.2 to JavaFX 8. The button action is not fired on pressing the Enter key, only on pressing space.
Sample:
public class ButtonTest extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
Button l_button = new Button("Hit me");
[Code] ....
Run the sample Application in Java 7 with JavaFX 2.2: both pressing Enter and Space print "auau" to the console if the button is focused.
Run the sample Application in Java 8: only pressing Space prints "auau"
How can this be? Hitting a focused button on Enter is a standard behavior on Windows platforms.
View Replies
View Related
May 26, 2014
This is what i've done so far.
table.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ENTER) {
model.addRow(new Object[]{"", "","",""}); } }
public void keyReleased(KeyEvent e) { }
public void keyTyped(KeyEvent e) { } } );
I've added JTable to JPanel and used DefaultTableModel. I have to add a new empty Row to table after i press enter key. But somehow I've not been successful so far.
View Replies
View Related
Oct 13, 2014
so I had to create a program that allows the user to enter a day using a number and then enter a year and after they did that it would create an entire calendar for that year ..so I have that but the only issue is I can not get the numbers to line up neatly.how to do the entire thing in loops, I tried a couple in here..what this would look like as loops instead of switches and cases and if else
import java.util.Scanner;
public class Calendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
[code]....
View Replies
View Related
Mar 23, 2015
I'm just trying to append new employee information to a previously created file. When I type yes to add new employee and enter a string, the data does not appear in the file.
Java Code:
public class Records {
public static void main(String [] args) throws IOException {
Scanner input = new Scanner(System.in);
FileWriter fw = new FileWriter("dbs3.java", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
[code]....
View Replies
View Related
May 21, 2015
I have a JTable that is being used to display, and edit data from a database. When the user presses the Enter key on the keyboard I want a carriage return to occur in the cell they are typing in. I do not want the cursor to go to the next row which is the default behavior.
View Replies
View Related
Feb 11, 2015
Write a program called ProductCatalog that prompts the user to enter the number of products in the product catalog. The program should then prompt the user for the name and the price of each product in the product catalog. Once all of the products have been entered, the program should output the product information (name and price) of the most expensive product in the catalog. Your solution must use a for loop repetition structure and should use the Product class included in labfiles05.zip to keep track of the product with the highest price. Here is sample output:
Enter the number of products: 3
Enter the name of product 1: iPod
Enter the price of product 1: 158.99Enter the name of product 2: iPad
Enter the price of product 2: 518.99
Enter the name of product 3: iPadMini
Enter the price of product 3: 304.49
Most Expensive: Product [name=iPad, price=518.99]
Your solution should not use an array to keep track of all the product information entered.
I am having trouble with my code, with the For loop and then calling the methods from the Product class into the ProductCatalog. How should I approach this program.
Here is the Product program.
public class Product
{
private String name;
private double price;
public Product(String theName, double thePrice) {
name = theName;
price = thePrice;
[Code]...
Here is the ProductCatalog class where I call the methods from Product class. The For loop is what I am having trouble with as well.
import java.util.Scanner;
public class ProductCatalog
{
public static void main(String[] args) {
double number;
String product = " ";
double productCount = 0;
[Code]...
View Replies
View Related
Feb 8, 2014
I want to limit the program to only accept a 12 digit input and an integer value but I don't know how to program it,
import java.util.Scanner;
public class testing4
{
public static void main(String []args) {
Scanner reader = new Scanner(System.in);
String input;
[Code]...
View Replies
View Related
Jun 1, 2014
The exercise sounds like this : Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid , as shown in the following sample run (my code displays correctly the first 9 lines):
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7
The problem is when i input a number greater then 9 as it requires 2 spaces . I m pritty sure i solved it incorrectly or at lost not optimal as i m using a string that decreases on each line to create the pyramid effect.
import java.util.*;
public class C5_17 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of lines: ");
[Code] ....
View Replies
View Related
Feb 7, 2014
I need to allow users only enter integer into a String variable, "input" and I am not sure what statement to use.
import java.util.Scanner;
public class assq2b {
public static void main(String []args) {
Scanner reader = new Scanner(System.in);
String input,b;
[Code] ......
View Replies
View Related
Jan 6, 2014
I am trying to get a user to enter an integer (registration number) between 500 and 5000. if it is below 500 and over 5000 the user should get a prompt "invalid number" and "non-numeric character". See my code below. it is not working when i enter invalid numbers.
import java.util.*;
public class Infomation{
public static void main(String args []) {
Scanner in = new Scanner(System.in);
System.out.print("Student Number:");
int sn=in.nextInt();
[Code] ....
View Replies
View Related