Store Name SD Array And Display Room And Floor Number Whose Name Is Entered
Sep 12, 2014
I have to store the name SD array and display the room and floor no. whose name is entered but i am having a problem with the logic part. The answer is coming to be wrong
import java .io.*;
class hotel
{
public static void main()throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(read);
String ar[][] = new String[5][10];
[Code] ....
View Replies
ADVERTISEMENT
Apr 15, 2014
Write a Java program that asks the user to store 10 numbers in an array. You should then print the array in the order entered and then print in reverse order. However, instead of putting all the information in the main, you should use a class called PrintIt. The PrintIt class should have an instance variable that is an array to hold the numbers. You should have a method that will print the array in the order entered. You will also need a method to print in reverse oder. Then create a tester class that asks the user to enter 10 numbers and puts them in an array.
So far I've got this.
public class printIt {
int i;
int [] numArr = new int [10];
public printIt () {
i = -1;
[Code] .....
Output:
Enter a number:
8
34
Forward:
8
34
Reverse:
34
8
end
what i want as an number is being able to print out 10 numbers but this only lets me do two numbers. Why is that so?
View Replies
View Related
Nov 6, 2014
I have returned with yet another problem but I think this one might be a bit easier to fix.
So the whole MO of this program is to take user input, and display the sum of the digits of the number they entered. I am supposed to do this by utilizing methods. So far this is what I have and when I compile it tells me that it "cannot find symbol", which I don't understand as I define what "m" is in the for loop. The other error is that it says:
"Exercise6_2.java:22: error: incompatible types: possible lossy conversion from long to int
return result;
^
I don't understand why it's giving me this error nor do I understand why result seems to inherently be an int. (Also the public static int sumDigits(long n) method was given to me by the book so that is what I am supposed to use).
import java.util.Scanner;
public class Exercise6_2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a integer");
long n = input.nextLong();
[Code]...
View Replies
View Related
Nov 8, 2014
So I need to generate 10 random integers in the range 1-20 but i have to store them in an array called numbers. Then I have to call a method called displayArray which displays the contents of the array and for the assignment i have to use a for loop to traverse the array. The method header for the displayArray method is:
public static void displayArray(int[] array)
This is what I have done
public class RandomIntegers {
static int numbers = 0;
public static void displayArray(int[] array) {
System.out.println(numbers + "Numbers Generated");
[Code] .....
View Replies
View Related
Feb 18, 2014
i am trying to store a number of different value cards for a number of players. E.g there can be 2 , 4 or more players and each player can have any number of cards.
I have decided to use an arraylist for cards and tried using an array for players. But after coding and reading some information online, i realised that it is not possible to have an array of arraylist.
View Replies
View Related
Aug 10, 2014
initialize the min and max to be the first numbers entered, need to improve the code, because if the number entered is < 0 there is an error. but i dont understand how i would initialize to the first number entered, my understanding is tha if the user enters a 5 , then i should initialize to value 5, but i cant anticipate what the user will enter. I could initializa to null, but that still is not the first number entered.
int min = 0;
int max = 0;
int option = JOptionPane.YES_OPTION;
while ( option == JOptionPane.YES_OPTION){
[code]....
View Replies
View Related
May 9, 2014
write a program that will ask the user to enter five numbers.using If statements if each number entered in greater than zero
import.java.util.Scanner;
public class Java3 {
public static void main(String[] args) {
function addNumbers(n1, n2, n3, n4, n5){
var finalNumber = 0;
[Code] ....
addNumbers(1, 2, 3, 4, 5,);
View Replies
View Related
Apr 24, 2014
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber type="currency" value="12345.6789"/></p>
<input type = "text"/>
This one is working if i set value in fmt but what i want to happen is when i enter a number in textbox it will be fommated on the format that i want, so i think i need to an of og text and set it into value of fmt? <y plan is when I enter a number in textbox it will automatically formatted ....
View Replies
View Related
Feb 21, 2014
I need to find if the number entered by the user are consecutive or not!
Ex:this should return a true!! This should return false!
(1,2,3) (3,5,7)
(3,2,4) (1,2,2)
(-10,-8,-9) (7,7,9)
My program seems to work ok when i enter number in order like 1,2,3 = true , and all the numbers for false seem to be working as well! my problem is when i enter number like 3,2,4 that are not in order but still are consecutive!! I thought that another if statement would be the solution but i have tray several different ones and still can't make it work !!!
Java Code:
import java.util.*;
public class Consecutive{
public static void main (String [] args){
Scanner console= new Scanner(System.in);
System.out.println("Enter three numbers");
String numbers = console.nextLine();
[[Code] .....
View Replies
View Related
Sep 15, 2014
What I am trying to do here is allow input to loop until 0 is entered for the product number. When 0 is entered, it should then dump the total for each individual product. I've tried it about a dozen different ways and have yet to be able to get the loop to function as intended. The way I have the code below, the loop will not function at all (where as before it looped, but never finished).
import java.util.Scanner;
public class Sales {
public static void main(String[] args) {
double total1=0.0;
double total2=0.0;
double total3=0.0;
double total4=0.0;
double total5=0.0;
int product;
[Code] ......
View Replies
View Related
Sep 12, 2014
I am having a problem with SD array .i have to find the ASCII no. of names entered.
import java .io.*;
class ASCII
{
public static void main()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
[Code] .....
View Replies
View Related
Feb 25, 2015
Java program : For this assignment you are going to write code for the following class:
MathOnThreeNumbers
Here are the specifications of class MathOnThreeNumbers:
Methods of class MathOnThreeNumbers:
1. inputThreeNumbers
2. getAverage
3. getSum
4. getNumberOne
5. getNumberTwo
6. getNumberThree
Constructor of class MathOnThreeNumbers
write a constructor that initializes the first, second, and three numbers to 1, 2, and 3 respectively.
Specs for the methods methods:
1.
name: inputThreeNumbers
accessibilty: public
arguments: none
what it does: asks the user for three numbers of type double
2.
name: getAverage
accessibilty: public
arguments: none
what it does: returns average of the three numbers
3.
name: getSum
accessibilty: public
arguments: none
what it does: returns sum of the three numbers
4.
name: getNumberOne
accessibilty: public
arguments: none
what it does: returns the first number entered by the user
5.
name: getNumberTwo
accessibilty: public
arguments: none
what it does: returns the second number entered by the user
6.
name: getNumberThree
accessibilty: public
arguments: none
what it does: returns the third number entered by the user
Here is an example of how the class MathOnThreeNumbers works. The following code produces the output displayed after the code.
MathOnThreeNumbers mm = new MathOnThreeNumbers();
System.out.println("first: " + mm.getNumberOne());
System.out.println("second: " + mm.getNumberTwo());
System.out.println("third: " + mm.getNumberThree());
mm.inputThreeNumbers();
[Code] .....
View Replies
View Related
Apr 8, 2014
Basically i have a question ask me to write a program that read integer from keyboard until a negative number is entered, and then print out the max and min out of the number i have entered.
This is what i have done already which works, but i need to ignore the negative number when print out max and min...which i dont know how to do so. when i compile this program now it will always give me the negative number i enter at the end as minimum. which i need to ignore
Also if negative number is entered at once the program should print a error message say max and min are undefined.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int large = Integer.MIN_VALUE;
int small = Integer.MAX_VALUE;
while(true) {
System.out.print("Enter a integer: ");
int n = in.nextInt();
[Code] ....
View Replies
View Related
Oct 26, 2014
My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.
When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.
//stephanie
import java.util.Scanner;
public class gradeAverage
{
public static void main(String[] args)
[code]....
View Replies
View Related
Jun 28, 2014
I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.
What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:
class factorial {
public static void main( String[] args) {
Scanner scan = new Scanner(System.in );
int num;
int product = 1;
[Code] ....
View Replies
View Related
Nov 2, 2014
I want to store an image/file into oracle database using jsp.
I have written code to store data when am running in my machine it is working fine, but not working in server throwing an error saying that "The system cannot find the file specified."
I am attaching the code what am written.
View Replies
View Related
Jan 5, 2015
I am not getting the result I am looking for, but I'm sure I'm on the right track. I have an array, names + times of marathon runners, and should end up with a program that displays the slowest runner, and the next-slowest runner.
Currently, I get this:
The lowest time is 273.
The lowest time is 243.
Changing names.length to times.length changes nothing.
for (i = 1;... ) changes nothing.
The displayed number should currently only be 243. Why is it displaying 273 first, and at all?
The code:
class Marathon {
public static void main (String[] arguments) {
String[] names = {"Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex", "Emma", "John", "James", "Jane", "Emily", "Daniel", "Neda", "Aaron", "Kate"};
int[] times = {341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265};
int min = times [0];
for (int i = 0; i < times.length; i++) {
if (times[i] < min){
min = times[i];
System.out.println("The lowest time is " + min +".");
}
View Replies
View Related
Dec 29, 2014
ex
Sample input:2340980
Sample Output:23498
this is the program i have tried but is dosent work
import java.util.*;
class zero
{
public static void main(String args[])
{
[Code]....
View Replies
View Related
Dec 24, 2014
I am trying to use parallel arrays to store names and job titles, then display the name/job title combo depending on which is entered. I have always struggled with arrays, so I'm sure that's where my issue is, but I am not sure how to resolve this one. I tried to use the toString() method with the jobs to see if that would allow the job title to match to one of the titles listed, and I tried to not use the toString() method with the names to see if that would allow the name entered to match to one of the names listed in the array. Both options only display the "invalid" message no matter what I enter. What would be the best choice to use the arrays to properly display the information ....
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JEmployeeTitle2 extends JApplet implements ActionListener
{
Container con = getContentPane();
[Code] .....
View Replies
View Related
Jul 8, 2014
I have a problem with my application. It supposed to store 4 different Room objects but when I entered one only it stores tat object variables into all my Array elements. I just need it to store any number of objects as long as it is less than 4.
Java Code:
import java.util.Arrays;
import java.util.Scanner;
import javax.swing.JOptionPane;
class TestRoom {
public static void main(String [] args)
{
String[] roomsInHouse = new String[4];
[Code] .....
View Replies
View Related
Sep 11, 2014
If you see in the code below where I print "Would you like to use previous key" I need to be able to save the previous key answers to be used again.. not sure how to go about doing this..
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String[] studentName = new String[20];
int[] studentAverage = new int[20];
Scanner input = new Scanner(System.in);
[Code] .....
View Replies
View Related
Jun 10, 2014
/**
* Auto Generated Java Class.
*/
import java.util.*;
public class Hangman {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int guess;
boolean revealed[] = {false, false, false, false, false};
String word [] = {"c", "a", "n", "a", "d", "a"};
[Code] ....
I am not sure how to make the program check if the letter entered by the user matches the one in the array. also i am not sure how to make the program run again with a new word.
View Replies
View Related
Sep 24, 2014
I am doing the home work to create a mini hotel reservation system which should be able to write the data into .txt file.
case study:
1. Have 2 different types of room (1- Suite 2- Deluxe)
2. Room Rate (Suite - $500per night, Deluxe - $300per night)
3. Both rooms can accomodate 2adults and 2childs
4. Checkin time: 2pm, Checkout 11am
5. Room status = occupied once guest checkin, Room status = vacant once guest checkout
6.For checking require (ID,Full Name,Address,Nationality,Flight no/Vehicle Reg no,number of people,check-in date, check-out-date,payment detail
7.Front desk search the vacant room to be assigned to the guest
Functions:
1. View all rooms
2. Add Customer to a room
3. Display available room
4. Delete customer from a room
5. Find room from customer name
6. Exit
Files:
One file use to store room info. (to be retrieved by program)
One file use to store rate info. (to be retrieve by program)
One file use to store the booking details (to be created and write by the program).
Currently I have write a program but only compiling and display the output to the console. How to modify my code below to be able to save to the .txt file
Here is the code:
import java.util.*;
import java.io.*;
class Customer {
private String name;
private int room;
public void setName(String name) {
this.name=name;
[code]...
View Replies
View Related
Apr 22, 2015
a. Write a Java program to input 10 integer numbers into an array named fmax and determine the maximum value entered. Your program should contain only one loop, and the maximum should be determined as array element values are being input. (Hint: Set the maximum equal to the first array element, which should be input before the loop used to input the remaining array values.)
b. Repeat 1a, keeping track of both the maximum element in the array and the index number for the maximum. After displaying the numbers, display these two messages:
The maximum value is: _________
This is element number __________ in the list of numbers
Have your program display the correct values in place of the underlines in the messages.
c. Repeat 1b, but have your program locate the minimum value of the data entered.
I did parts a and b but for part see i just want to know if i did it correctly or not
import java.util.Scanner;
public class MinimumValueArray {
public static void main(String[] args) {
//Variable Declaration
Scanner keyboard = new Scanner(System.in);
int size = 10;
[Code] ,.....
When I run it i get this The minimum value is 0.0
The element that holds the value is 0 right away. is this right for the minimum or am i supposed to enter values and it will display the minimum value like in parts a and b wit the maximum? will the minimum just always be 0 or ?
View Replies
View Related
Jan 30, 2015
I need to create a code for this asign:
Write a program that computes the cost of painting and installing carpet in a room. Assume that the room has one door, two windows, and one bookshelf. Your program must do the following:a. Prompts the user to enter, in feet, the length, width, and height of a room.
A. Read the dimensions of the room.
b. Prompts the user to enter the width and heights, in feet, of the door, each window, and the bookshelf. Read these quantities.
c. Prompts the user to enter the cost, per square foot, of painting the walls. Read these quantities.
d. Prompts the user to enter of cost, per square foot, of installing carpet. Read these quantities.
e. Output the cost of painting the walls and installing the carpet.
View Replies
View Related
Oct 9, 2014
So i'm writing a for loop to convert any number entered to base 10 with any base provided as well. My code does not work because I need a way to reverse the code order, so the new number is printed correctly with the given base. My code so far:
public static void main (String[] args) {
Scanner kb = new Scanner (System.in);
System.out.print("Enter a number :: ");
int numOriginal = kb.nextInt();
System.out.print("Enter a base :: ");
int base = kb.nextInt();
[Code] .....
newBase has a problem with how it calculates the new number, looking for correct newBase code for conversion?
View Replies
View Related