Write A Program Where User Inputs A Month Between 1-12

Sep 21, 2014

I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:

insert "}" to complete StatementKALENDER_3.java
insert "}" to complete BlockKALENDER_3.java

The code:

import java.util.*;
import java.util.Scanner;
public class KALENDER_3
}
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.print("Skriv ett manadsnummer: ");

[code].....

I think I have just forgot to put in a few { } symbols, maybe an open loop?

View Replies


ADVERTISEMENT

Parallel Arrays - User Input Integer 1-12 / Output Name Of Month And Number Of Days In That Month

May 11, 2015

I've been working on a question using parallel arrays where the user inputs an integer 1-12 and the output will be the name of the month and the number of days in that month. This is what I have so far

import java.util.*;
public class DaysMonth
{
public static void main (String args[]) {
Scanner keyIn = new Scanner(System.in);
int[] days = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

[Code] ....

After I enter the user int it just ends.

View Replies View Related

Java Program That Will Ask A User To Input Grades Until User Inputs Sentinel Value

Apr 9, 2014

Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".

View Replies View Related

Write A Program For Converting Positive Binary Inputs Into Hex

Sep 29, 2014

I am trying to write a program for converting positive binary inputs into hex.Why am i getting this errors while compiling my binary to hex converter..

Exception in thread "main" java.lang.NumberFormatException: For input string: "148.0"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Long.parseLong(Long.java:441)
at BinToHex.convertbintohex(BinToHex.java:24)
at Test.main(Test.java:4)

Here is my BinToHex class

import java.io.*;
public class BinToHex {
double tempDec,fractionpart;
long longofintpart,templongDec;
String inpu ="1001.01";
String hexOutput,intpart,tempDecString,hex = null;

[code]....

View Replies View Related

User Inputs His Full Name In A String From Keyboard / Program Will Give His Initials As Output

Jan 5, 2014

Following is the code for my assignment where a user inputs his full name in a string from keyboard. It should be done using BufferedReader. The program will give his initials as output.

############################

For example: User inputs-> Ram Kumar Das

Program Returns-> R.K.D.

I am written the following piece of code. It does not return the correct output. If "Ram Kumar Das" is given as input, it gives R.K.K. as output. Arrays and objects are strictly not allowed.

Java Code:

import java.io.*;
public class Assignment
{
static int i=0;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main (String args[]) throws IOException

[Code] ....

View Replies View Related

Program Store Input Of Rainfall For Each Month - Print Out Month With Least And Most Rainfall

May 1, 2014

I have written program for rainfall that will store and give total, average, least and most. The program stores the input of rainfall for each month. However at the end it suppose to print out the month with the least and most rainfall. I am getting this on the print for

The month with the most rainfall: [Ljava.lang.String;@79a7bd3b

and for

The month with the least rainfall: [D@7378aae2[Ljava.lang.String;@79a7bd3b

. What have i done wrong?

View Replies View Related

Write A Program Which Prompts User To Enter 4 Grades Between 0 And 100

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

Write A Program That Reads From User Several Lines Of Input

Mar 24, 2014

a. Assume that we have a list of employees' names of a company and their ages. Write a program that reads from the user several lines of input. Each line includes an employee's name and his/her age (as an integer). The program should calculate and print the following:

- The average age of all employees (rounded to 2 decimal places).
- The oldest employee and his/her age.

Hints:

You could assume that the user will insert valid data and at least one employee.
You could assume that the oldest employee is only one person.
User could stop the program via entering the word "end" as an employee's name.

Sample Input and Output: In each line, insert an employee's name and his/her age To halt the program, insert "end" as an employee's name

Adam 30
Tom 41
Ted 45
Karl 30
end

The average age of all employees is 36.50.The oldest employee is Hisham whose age is 45

View Replies View Related

Write A Program That Prompts User For 3 Double Numbers

Feb 15, 2015

So i need to write a program that prompts the user for 3 double numbers x, y, z that outputs 2x^3 + 3y^5 + 3x^3y^2 +xyz with

(1) 4 digits precision
(2) with a ',' to separate thousands
(3) all digits of the result including the precision are put to 20 positions (from right to left)

I am not really sure what it is suppose to look like or how to start it.how to mix Math.pow with multivariable and printf.

View Replies View Related

Write A Program In Which User Will Select A Text File

Mar 30, 2015

i am trying to write a program in which the user will select a text file(which contains information that the graphical output will be based). I have successfully set up my file chooser however when i select the text file,i do not get any graphical out put. please see attached .zip file for code.

View Replies View Related

Write Java Program That Asks User For List Of Names?

May 21, 2015

I am trying to write a java program that asks the user for a list of names (one per line) until the user enters a blank line. At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the user entered the name in the program. I am supposed to use an ArrayList for this problem.

My idea for a solution is to create an ArrayList<String>, read each name, i.e., line, entered and then to see if that name is already in the ArrayList. I created a for loop to check each element in the ArrayList but when I try to assign an element to a string variable I get the error "Type mismatch: cannot convert from Object to String". Not sure why that is happening because the ArrayList is defined as a String list.

Here is the code so far.

/*
* File: UniqueNames.java
*/
import acm.program.*;
import java.util.*;

[Code].....

View Replies View Related

Write A Program That Prompts User To Enter Two Positive Integers And Prints Their Sum

Jan 9, 2015

Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:

Enter two positive integers: 5 3
The sum is 8.
The product is 15.
The difference is 2.
The quotient is 1.
The remainder is 2.

import java.util.Scanner;
public class TwoIntegers {
public static void main(String[] args) {
System.out.println("Enter two positive integers: ");
Scanner userInput = new Scanner("System.in");
int integer1 = userInput.nextInt();
int integer2 = userInput.nextInt();

[code]....

View Replies View Related

Using User Inputs In Other Class?

Feb 8, 2014

I have a LoginScreen class and one other class in my project. I want use user inputs (Username And Password) on other class if users details is true. I am stcuk at this point because when user attempt to Login connection is succesfully and other frame is coming to screen but i can reach user details anymore. Let me explain with codes;

LoginScreen class

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package deneme3;
import java.sql.Connection;

[code]....

You can see Button Action in MainProgramWindow " System.out.println( ??? );" How i can retrieve users inputs from this class ?

View Replies View Related

Increasing Counter When User Inputs C / D Or E

Feb 15, 2015

We are writing our own classes and methods. My instructor has provide the code

/*-------------------------------------------------------------------------
import java.util.*;
public class Assignment5 {
public static void main (String[] args) {

[Code].....

I am having trouble with the question counter. I need the counter to increase when c, d or e are entered. I think I need to set up a if or while loop but I'm not sure how to setup the variables. This is what I have for the counter so far.

[public int getNumberOfQuestions(){
numQuestions = 0;
numQuestions ++;
return numQuestions;
}

View Replies View Related

Filling Array With Three Of User Inputs

Aug 9, 2014

I realized that I was not filling the array with anything but now I'm having issues filling it correctly. It's only filling the array with three of the user inputs ....

import java.util.Scanner;
public class DriverSort {
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
Sorter sorter = new Sorter();
int choice; // variable which says which sorting algorithm to use

[Code] .....

View Replies View Related

Write A Program That Prompts User To Enter A Password And Displays Valid Password

Dec 3, 2014

My homework is asking me to write a program that prompts the user to enter a password and displays "valid password" if the rule is followed or "invalid password"

Sample
enter a string for password: wewewx
valid password

It's being graded on
Design of my GUI
Dialog box
User friendliness
Creativity

My current issues with the current code I have written is simply the password doesn't work unless it starts with 2 digits, the other order it displays as wrong. and I have no idea how to add a GUI.

import java.util.*;
import java.lang.String;
import java.lang.Character;

[code]....

View Replies View Related

Storing Multiple User Inputs In Array

Feb 28, 2015

I need to generate a league table in Java based on results provided in the shape of user input. I have the 6 teams in an array. I need to ask the user how many wins, draws, losses each team has had.

for (String element : teams) {
System.out.println(
"Please enter the number of wins, draws and losses for " + element);
int[] wins = new int [6];
int[] draws = new int [6];
int[] losses = new int [6];
}

How do I pull 3 separate values from the user and then store each value in a separate element of each array? so if one team wins 3, draws 2 and loses 1 - I need to put 3 into the wins array, 2 into the draws array and 1 into the losses array? I then need to total all this in a table.

View Replies View Related

Return A String That Holds User Inputs

Apr 18, 2015

I'm working on an assignment for my Java Programming class that requires me to work with Multiple Classes.

Overview of the assignment: Create a "Database" that allows a user to input information about a College Class.

My program has three Classes:

The information that must be tracked in the Course Class is:
- Section Number
- Instructor
- Classroom
- Students (an ArrayList of class Student)

The information that must be tracked in the Student Class is:
- Name
- Major
- GPA
- Hours

The Driver class will use the main method to print the user a prompt asking for inputs, then display all of the user's inputs after he/she wished to exit the program.

I'm having no trouble with asking the user for inputs and then checking the validations for the inputs, I'm currently struggling with return a String that houses all of the user's inputs for the variables above. The information must be returned in a method called toString(). Both the Student and Course Class must have a toString() method that returns the information in the class (value of the variables), I must then call upon these methods from the main method of the Driver Class to print them back to the user.

The toString methods within the Student & Course Classes are at the bottom of the code

To Summarize: What I need to do within the toString() methods to return the values the user has inputted for the various variables? Such as.. Should I pass something through the method? Do I need the this keyboard to pass through the variable again? I just fear that I'm currently misunderstanding a very critical part of programming.

My Driver Class

import java.util.Scanner;
public class Driver {
Course courseInputs = new Course();
Student studentInputs = new Student();
public static void main(String[] args) {

[Code] .....

View Replies View Related

Need To Count Strings That How Many Inputs From User Were Numbers

Jan 30, 2014

import java.util.Scanner;
public class CountStringNumbers { // show the number of Strings that were numbers . . ..
public static void main(String []args){
int count = 0;
int countNumbers=0;
Scanner input=new Scanner(System.in);

[code]...

can count the numbers from 0-9 if the user puted but if it is 10 it doesnt count it , and i need to write all the numbers to have that option. . . . Is there an easy way that includes all the numbers? like if(word.equals(number)){<<<???? (numbers) i know htat doesnt work but is there anything similar ?? ??

countNumbers++;
}
System.out.println("Type Something , , , and to end the the termination type STOP");
word=input.nextLine();
count++;
}
System.out.println("You wrote "+count+" lines wich from those lines "+countNumbers+" were numbers and the programe terminated ");
}
}

View Replies View Related

Equivalent Arrays - Comparing 2 User Inputs To Determine If Same

Mar 4, 2015

I have been stuck on this for the past 2 hours, basically we have to compare user input, put user input into an array and compare for equivalency. An example of the program:

Array 1: 1 2 3 4 5 6 7 8
Array 2: 1 2 3 4 5 6 7 8
Array 3: 1 2 3 4 5 6 7 8 9
Array 4: 1 2 3 4 5 6 7 8

Array 1 & 2 are equal
Array 1 & 3 are not equal
Array 1 & 4 are not equal.

This cannot be done by importing Java.util.Array at all!! (my research only find this to compare arrays ) which is why I am having trouble starting off. My code thus far:

import java.util.Scanner;
public class Lab07b {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Integer 1:");
int a = input.nextInt();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Taking Inputs Based On Previous User Input

Jun 7, 2014

I'm developing a Swing application for the first time. To test my application, I have currently hardcoded some text labels and fields in a JPanel, so that a user can enter input details for a maximum of 3 segments. But this limits the maximum number of segments to 3. However, the requirement is that when the user enters the number of segments (could be greater than 3 as well), corresponding number of input sets need to be taken.

Screenshot attached, with values entered.

Basically I want to know how I should go about taking the inputs from the user.

View Replies View Related

FileWriter - Print Initial Attributes And User Changed Inputs Into A File

Oct 10, 2014

I am having an issue with using FileWriter to print some text to a text file. In the following code, I am supposed to be able to print the initial attributes and the user changed inputs into a file but all I am getting is the memory locations of the objects I created in one long line.

package project3final;
import java.io.*;
import java.util.*;
public class Project3Final {
static class Instrument {
char [] stringNames = {'E', 'A', 'D', 'G', 'B', 'E'};
private final String instrumentName;

[Code] .....

View Replies View Related

How To Create JavaScript To Find Current Month And Current Day Of Month

Mar 17, 2015

I want to be able to use the current date to solve a math problem, specifically as follows:If today is March 17, the math problem of the day should be:

(Month times Day of Month) + 99 = Answer of the Day

(3 x 17) + 99 = 150

How can I create a java script to find the current month and the current day of month, multiple those two together, then add 99 and display the answer as a result.

View Replies View Related

Developing A Program That Inputs Telephone Numbers

Jan 26, 2014

Develop an algorithm for a Java program that takes as input a single letter and displays the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way:

2 = ABC 3 = DEF 4 = GHI 5 = JK 6 = MNO 7 = PQRS 8 = TUV 9 = WXYZ

The screen dialog might look like this: Enter a single letter, and I will tell you what the corresponding digit is on the telephone. R The digit 7 corresponds to the letter R on the telephone.

The program should display a message indicating that there is no matching digit for any non-alphabetic character entered by the user. Also, the application should recognize only uppercase letters. If a user enters a lowercase letter, the program should display an error message. Prompt the user with an informative message for the input value as shown above.

The application should include the input letter as part of the output.

Write the algorithm to solve this problem including steps for prompting the user, getting input from the keyboard, and displaying the results.

Write the Java program that you designed, using your algorithm as a guide. Use your algorithm as comments in the body of the main method.

Use proper indentation, and meaningful identifiers throughout the code.

View Replies View Related

Program For Converting Positive Binary Inputs Into Hex - Unexpected Output Java

Sep 30, 2014

I am trying to write a program for converting positive binary inputs into hex. in the hex output the point (".")is missing.

Suppose my expected output is e7.6 , but i am getting e76.

Only the "." is missing.

Here is my BinToHex class..

import java.io.*;
public class BinToHex {
double tempDec,fractionpart;
long longofintpart,templongDec;
String inpu ="11100111.011";
String hexOutput=null,tempDecString,hex = null;
 
[Code] .....

Here is how decimal fraction is converted into hex or here too...

View Replies View Related

Write User Input To Text File

Dec 8, 2014

I need to write a program where the user inputs name, age, email, and cell and write the user inputs to a text file. I need to have it so the file can be added to if more than one set of information is added. Currently, every time I click the button, the file is overwritten instead of added to. How do I correct this? Current code is as follows:

try
{
FileWriter writer = new FileWriter("ContactInformation.txt");
BufferedWriter bw = new BufferedWriter(writer);
nameTextField.write(bw);
bw.newLine();
ageTextField.write(bw);
bw.newLine();
emailTextField.write(bw);
bw.newLine();
cellTextField.write(bw);
bw.newLine();
bw.close();
nameTextField.setText("");
ageTextField.setText("");
emailTextField.setText("");
cellTextField.setText("");
nameTextField.requestFocus();
}

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved