Console Based Interface Loop
Mar 11, 2015
I am implementing a console based interface for an assigment. I've got a DAO interaces and implementations ready and I am stuck on a loop that checks whether to display logged in menu or logged out menu.
public static void main(String[] args) throws SQLException {
Main consoleInterface = new Main();
boolean runningLoop = consoleInterface.isRunning();
boolean loggedOutLoop, loggedInLoop;
while(runningLoop) {
[Code] ....
So when this runs it should show loggedIn() method only and only if the condition is not met. At the start when program runs I set loggedOutLoop = true and loggedInLoop = false. When I handle login I set loggedOut = false and loggedIn = true
What seems to happen is that the else statement doesnt work and the output I've got is only loggedOut() method displayed where I only want loggedIn() to be displayed without loggedOut().
View Replies
ADVERTISEMENT
Jul 2, 2014
Ask user to enter a name alphabet by alphabet, and print d whole word as output,,,,,, use while loop?Since i am new to JAVA..i have no clue on how to begin?
View Replies
View Related
Jun 9, 2014
Below code gets printed as output?
public interface I1 {
public void method();
}
public interface I2 {
public void method();
}
public interface I3 extends I2, I1 {
[Code] ....
View Replies
View Related
Jan 27, 2015
I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.
int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;
now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.
View Replies
View Related
Feb 25, 2014
Here's the code: it's while loop inside a for loop to determine the proper length of a variable:
for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "
[code]....
I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.
View Replies
View Related
Nov 2, 2014
I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.
Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.
After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.
The output of the program should something like this:
John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67
Code:
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
[code]....
View Replies
View Related
Feb 13, 2015
Trying to run my program after getting rid of code errors (I think) and now it doesn't produce anything but <terminated> in the console window. The produce is suppose to analyse text from a file and produce the percentage of words used
package com.project;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
[Code] ....
erfrf.jpg
View Replies
View Related
May 21, 2014
This is my program. All is working fine except stopping reading from console. Problem is that even after you write done if you are fast enough you are able to write more. As you can see I can't close scanner because of two inputs. Even so I tried to close it but problem was still here.
public static void main(String...args) {
System.out.println("Write first input:");
System.out.print(streamToString(System.in, ""));
System.out.println("Write secondinput:");
System.out.print(streamToString(System.in, ""));
[Code] .....
View Replies
View Related
Apr 2, 2014
How to clear console screen ? I am using Linux machine.
1) Runtime.getRuntime().exec("clear"); // this is not working. Not clearing the screen
2) for ( int i = 0; i < SOME_NUMBER; i++)
System.out.println();
2nd way is working but i think it is not a good option as i need to move scroll bar again and again.
View Replies
View Related
Feb 12, 2015
i need to take a txt file and turn it into a csv(comma seperated value) output on console but where to begin.
View Replies
View Related
Feb 8, 2015
"Write a java application that displays the following patterns separately one below the other.
Use for loops to generate the patterns. There are 4 Triangle patterns.
All asterisks (*) should be printed by a single statement of the form System.out.print('*');
This is 4-different patterns, not 1-pattern."
The first 2 triangles are right angles and is simple to make with a loop with in a loop
The 3rd triangle is like an inverted christmas tree and the 4th one is a christmas tree. ( It's not showing properly on the board so i deleted it). I can't seem to make the 3rd and 4th triangle line up properly it looks like this (the _ represents blank spaces on the console)
_____*_____
_____**_____
____***_____
____****_____
___*****____
___******_____
__*******
__********____
Notice how the sides of the triangle isn't straight and the triangle looks like its dancing, the assignment requires it to be a straight line. is there anyway to do this? This is suppose to be the output. all the lines of the triangle is straight and not jagged ...
public class myclass {
public static void main(String[] args) {
int counter = 1;
int counter2 = 1;
while (counter != 11){
EmptyLine();
[Code] .....
My code for those particular triangle is in the work because I cant figure out how to make it look like that.
View Replies
View Related
Nov 7, 2014
I want to input character data from the console without using the BufferedReader class. I tried using the Scanner class but the compiler shows an error. This is what I tried:
sc.nextCharacter();
sc.nextcharacter();
sc.nextChar();
Sc.nextchar();
Is there any way I can input character data without using the BufferedReader class?
View Replies
View Related
Jun 14, 2014
I have a multithreaded java program. I have a few worker threads which process data over a udp server. Then I have another thread for console input. The problem is when there is an error with one of the worker threads, and it prints to the console, my console thread loses "focus", that is, the while loop seems to no longer run. Here is the console thread:
Java Code:
public void run() {
Console c = System.console();
if (c == null) {
Logger.writeError("No console.");
System.exit(1);
}
while(true){
String login = c.readLine(">>>: ");
System.out.println("You entered: " + login);
}
} mh_sh_highlight_all('java');
When an exception is raised, it prints it to the console, and suddenly the program no longer shows the >>> prompt from above.
View Replies
View Related
Nov 4, 2014
I seem to be having a issue with my java console app what it should do is query a SQL DB and list the user details (userid, firstname ,lastname) from the user table, and the users stocks (stockname ,stockdiscription) associated to each user from the userstocks table if I'm thinking correctly!
I'm sure it is just a logical error, but I'm not sure of the way to get the out put I'm looking for. I will add the makeDB.java file and DatabaseQuery.java file as well as the current Exception(Run Time Exception) below.
**I have added other users and stocks manually - Not just what the MakeDB.java file inserts **
Output and Exception:
Stock holdings by User
User ID User Name
Stock - Description
-------------------------------------------
admin01 Default Admin
Exception in thread "main" java.sql.SQLException: ResultSet is closed
at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(JdbcOdbcResultSet.java:6647
)
at sun.jdbc.odbc.JdbcOdbcResultSet.next(JdbcOdbcResultSet.java:1248)
at DatabaseQuery.main(DatabaseQuery.java:45)
Press any key to continue . . .
Java Code:
MakeDB.java:
import java.sql.*;
import java.io.*;
public class MakeDB
{
public static void main(String[]args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
[Code] ....
View Replies
View Related
Mar 10, 2014
I have written a shell script which connects to oracle database and performs operation and returns some output message. Script works fine from command prompt. My requirement is to make it run from a web page which I have accomplished. I am getting the output of shell script on a different web page defined by HTML form action in my jsp file. Everything is working fine.
Below is the part of java class I have written:
=============
String fileName = "build_"+ request.getParameter("region");
String arg1 = request.getParameter("release");
String arg2 = request.getParameter("email");
ProcessBuilder pb = new ProcessBuilder(fileName,arg1,arg2);
Process p = pb.start();
InputStream inputStream = p.getInputStream();
[Code] ....
As shown above, my shell script accepts 2 arguements . User enters arguements in the fields provided which are passed to shell script by processbuilder. Script runs successfully and displays output [ success/error ].
But my problem is , the shell script takes nearly 1 hour to do its job in the database and untill then my web page keeps showing as busy. Whereas in command prompt, shell script displays messages as it runs and thus keeps the end user informed about its progress. However, when called from java it waits untill the shell script completes/terminates and finally displays all the messages at once. I want to know if there is a way to display the shell script output on web page as it continues to run in the background ( child process ).
I tried without the waitFor() function but no luck. It still waits for shell script to exit before displaying any message.
View Replies
View Related
May 1, 2015
I thought you can use PrintWriter to write to the console but when I run the following code I only get "abc" printed to the console.
import java.io.*;
class Class1{
public static void main(String...abc) throws Exception{
PrintWriter writer = new PrintWriter(System.out);
writer.println("test");
System.out.println("abc");
}
}
View Replies
View Related
Oct 14, 2014
I created a calendar program so when the user enters a day number and a year it would show the calendar for the year . My issue was that I could not get the numbers to line up neatly and how they should look . Also if its not to much trouble I would like to know how to turn this in to a loop .
import java.util.Scanner;
public class Calendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a Year");
int Year = scanner.nextInt();
[Code] .....
View Replies
View Related
May 9, 2015
I am having a great deal of frustration trying to use the scanner to get user input from the eclipse console. Here is what I am trying to do.
Print a menu for the user with options, take that (1) char input and run it into a switch statement for processing. I have that done and it is working fine.
If the user chooses to enter strings for storage, They are instructed to enter their string and press enter to complete that string entry. Then enter the next string and press enter, etc.
So I have a While loop for this. Get the scanner input, store it in the LinkedList, get the next scanner input, etc. I get the scanner string and store it in a Linked list. That works fine. The user is instructed to simply enter a blank string to end the entry procedure, like just press Enter on the new line without typing a new string.
The problem is the scanner doesn't seem to return anything for me to Test to close this procedure. How do I TRAP the fact that the user just pressed enter so I can end my procedure? I have tried next() and nextLine() and reset(), etc. And I am getting knowhere.
View Replies
View Related
May 26, 2014
Follow the //? FIRST and SECOND notes, then I understood that Java has GOTO as Keyword for future versions and that usually one can avoid GOTO using break inside the cycles, but I need a jump( salto) in the code.
import java.util.Scanner;
public class ArrayOrdinati {
public static void main (String[] args){
int[] Array = {5,3,1};
int e=Array.length;
int b;
[Code] .....
View Replies
View Related
Sep 3, 2014
What I'm tasked to do, is to make a simple Java class that forms a "V" based on whatever height the user would desire, made out of stars "*", and spaces " ".
For example, if a user desires a "V" with a height of 3, it would look print out something like;
* *
* *
*
Where a "V" with a height of 5 would look something like:
* *
* *
* *
* *
*
(That one didn't look too good, but you get the point, it's suppose to be 5 "high" and shaped like a "V"). The problem I have, is that I don't see what loops within loops within loops I would need to build something like this.
All the easy stuff like asking the user what height they want and such, I can handle, but I don't see how this thing is suppose to be coded, to print out a decent-looking and right-sized "V" in the console.
public static void main(String[] args) {
int height = 3;
for (int i = 0; i < height; i++) {
for (int j = 0; j < 2/(height+1)+1; j++) {
if(j == i) {
[Code] ....
Looked like something of a good start, and it drew me half (!) of the "V" in the size I wanted. Am I on to it here, or am I on the moon in terms of progress? I need the entire "V", not just a nice "".
View Replies
View Related
Dec 10, 2014
I have this very simple application just to test console input:
import java.util.ArrayList;
import java.util.Scanner;
public class WriteTester {
[Code]....
When I let it run, only every third entry is put into the array list and I have to hit "enter" three times for the "break" in line 21 to trigger. I cannot find out why.
View Replies
View Related
May 2, 2014
how to clear my java output console?
View Replies
View Related
Mar 30, 2014
I'm using eclipse to run my java program.
I want to be able to change the background color of the console when the user types in a particular command..
e.g User types: color blue
Then the background color of the console should turn blue
Is this possible and how would I go about doing it?
View Replies
View Related
Jul 22, 2014
I have a console application. One thread allows a user to directly input into a console. Another thread listens on a tcp port, takes input, processes it, and then writes it to the console. The work in different threads, but in tcp thread, one I call a method outside that thread that writes to console, it often gets stuck. here is a mockup of situation:
Java Code:
import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
[Code] ......
It often freezes on "Attempt 1". Before I used System.out there, I also tried console.writer() there but both freeze at that point often. Any situation where console or System.out.writeln freeze when working across threads and why it is occurring? It almost feels like one thread has locked the console so the others can't write to it.
View Replies
View Related
Apr 13, 2014
I am writing a class which formats console output as a table. It displays the type of an entry, the name of an entry, and the data for an entry. I am stuck on a required for loop which appends a tab character to a string, for formatting it as a table. It doesn't seem to be adding any of the tabs and I can't tell what I've done wrong. As far as I can tell the contents of the loop are never reached, and I can't make sense of it.
The ConsoleWriter class that contains the code that is in error...
Java Code:
package frontend;
public class ConsoleWriter {
private static String tabbedData(String data, int min) {
System.out.println(); //for debug
int tabcount = 0;
int len=8*min;
[code]....
View Replies
View Related
May 20, 2014
i want to know about to convert speech to text in java..,
i found some articles are released to achieve this target (Speech 2 text) by using the Google Speech API from Google console.
i have already account & using the Map & other API too. But i unable to found the Google Speech API now..,
Sample Link : Speech to Text Library for Processing (STT)
what shall i do to achieve my target..
View Replies
View Related