String Inputs And Outputs - Printing Information To Console
Mar 22, 2014
Write an application that asks the user to enter his/her first name, last name, birthday, and where you born (all fields type String) and prints their information to the console. Use the techniques discuss in class. The data must be encapsulated. The program must be coded in Notpad++ and compiled in the Command Prompt.
Output should be like this:
Welcome!
What is your first name? Carlos
What is your last name? De La Torre
When is your birthday? 08/12/1979
Where did you born? Puerto Rico
First Name: Carlos
Last Name: De La Torre
Birthday : 08/12/1979
Born in : Puerto Rico
This is what I have so far :
package myinfo;
import java.util.Scanner;
public class MyInfo {
private String name;
private String lastName;
private String birthday;
private String birthPlace;
[Code] ....
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
Jan 8, 2015
I have small problem in GUI. I have a text area which has to display my test orders now what is happening instead of the text showing up in the JtextArea its still printing to the console so this order code (yes i did not use proper code standers) runs though my order class fine but its not loading the text in the JtextArea
Order code
public static String testCase1(){
orders ords = new orders();
System.out.println("Test Case 1: " + "
" + ords.getOrderDetails());
return " ";
My jbutton code :
txtContent.setText(new orderTester().testCase1());
txtContent.setText(new orderTester().testCase2());
txtContent.setText(new orderTester().testCase3());
I have 10 test case to load in the jTextArea
View Replies
View Related
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
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
Feb 17, 2014
Pulling info from a string. I have a string which contains some results such as [United States of America 1 Netherlands 0, Canada 1 United States of America 1, United States of America 3 Russia 1, Norway 2 United States of America 1, Sweden 2 United States of America 4"]. Now based on user input I need to pull the numbers from this string and add them up. So if the user inputs United States of America it would pull 1,1,3,1,4 put that in an array and add it. I know how to sum the array just not sure how to get that information from a string,
View Replies
View Related
Mar 2, 2015
I am trying to make a program in which first I am entering number of charachters and then in nextline their is exactly that number of characters should be enter after than program should stop taking input from console..this is I have try so far
private static ArrayList<String> chars;
static String inputdata;
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
chars=new ArrayList<String>();
[code]....
View Replies
View Related
Apr 8, 2014
We were suppose to make a program for an assignment and the prof provided some codes to start of. What does this basically mean? How do i access the string arrays from consolelist?
class ConsoleInfo {
private String conTitle;
private double conPrice;
private int conQty;
private String conPic;
private static String empPassword;
ConsoleInfo(String title, double price, int qty,String pic)
[Code]...
View Replies
View Related
Dec 13, 2014
Here is the question with my Pseudocode:
Create an application that keeps track of students. The application should have 3 new classes.
1. Create a class which will represent an instance of 1 student:
I want to be able to display the user's name (Last, First), Age (in years as an integer) and GPA (to 2 decimal points). This class only needs a constructor and a toString method.
2. Create a Team class that will represent a group of students.
This class should allow the driver class to manage students for a given course. The class will keep track of the course name and section, the students in the class, and allow the driver to specify the max number of students to keep track of.
Methods:
1.Constructor
2.It should have a method to insert a single student into the array and return a Boolean indicating success or failure.
3.It should also have a method which returns a string with all of the course and student information formatted for display. You should make the name 12 characters long.
3. Create a driver class that will manage the whole process.
Pseudocode:
BEGIN Driver main method
Initialize student count to 0
Input size of the array
Instantiate a copy of the Team class
Input a student name (or quit)
WHILE (the student name is not quit)
Input student age
Input student GPA
[Code] ....
View Replies
View Related
Oct 14, 2014
What it is supposed to do is decide whether a ceiling fan is on or off, and describe it (color, area, speed). This is all user input (even pi) so it should decide whether to turn it on or off but for some reason skips over my if/else if statements all together.
I've tried changing it around a bit, looking up what my problem may be but this problem remains the same. my code:
import java.util.Scanner;
public class CeilingFan
{
final int slow = 1;
final int medium = 2;
final int fast = 3;
private int speed;
boolean on = false;
private double radius = 5;
private double pi = 3.1415;
String color = "blue";
[code]....
View Replies
View Related
Jul 28, 2014
I'm having an issue, I have a scanner (Scan.nextLine();) that scans the console for input to fetch the string "word". Then I want to fetch a character using Scan.findInLine(word).charAt(number);. The problem is that the console requires me to write 2 lines in order for the program to move on. I only want the program to scan for a word, and then move on with what it has instead of requiring 2 inputs.
View Replies
View Related
Jan 24, 2014
I am writing a Java permutation program, it takes in N and k and gives k amount of combinations based on N length.
That portion works, but the portion I have that does not work is when k is greater then 1, the array is then then printing strings out of index.
The perm algorithm ends on index - 1 for moving characters but then I push all those characters into an Array List, I would think I could print them off however I want from there but that is not the case. I'll include the minimum amount of code possible.
//permString = 1234 or something, it doesn't matter
//Use Case N = 4 k = 3, prints out 123,124,132,134 ect
//Use Case N = 4 k = 2, error index out of range but only on the printing function; the perm function doesn't take k and
//is based on length
//the "" is just an empty string
permNow("", permString);
}
[code].....
View Replies
View Related
Sep 18, 2014
I need to use print not println to declare stuff and I need to have string literals I think that's /n. Now when I compile it just shows row1, row2 ect. Why does it work like that?
public class art {
public static void main(String[] args) {
//local variables
String row1= "***********************";
String row2= "** *** *** **";
String row3= "** ***** ***** **";
[Code] ...
View Replies
View Related
Apr 26, 2015
This is the code that I have so far, It will only print out the digit if it is entered first..How to I get it to print out all digits? and I am getting an error that the c is not initialized
import java.util.*;
//Write a program that prompts the user for some text. Output only the digits in that text. Hint: Use a loop and the Character.isDigit method.
public class Q1
{
[Code].....
View Replies
View Related
Apr 20, 2014
Currently, my program converts Long values to String. And when I test it out, it do print out the correct output. However, when the converted String value is passed over to be written in a text file, it seems that BufferedWriter isn't printing out the outcome that it's supposed to be.
saltVs = Long.toString(saltV);
System.out.print(saltVs); //will print out 79723172
Now the problem is here...It only prints out the last digit of the String value (instead of 79723172).
Here is my FileWriter/BufferedWriter part.
Why is that when I run my program using command prompt, it prints out the output that I wanted, but however when it comes to writing to the file, it doesn't come out right.
View Replies
View Related
Apr 12, 2015
Here is my program. I have to add the outputs from variable 'done' together. It seems to not work inside or outside the loop.
//A program that will find the last/check digit of a Book ISBN number.
import java.util.*;
public class ISBN {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("Enter the ISBN number>");
String isbn = kb.nextLine(); //Even though the ISBN code is a number,
[Code] .....
View Replies
View Related
May 15, 2014
I'm making an armor class. I also made a test for it to ensure it works, but something seems to be wrong. I'm not getting the expect outputs when I ask it to give me a println of the variables.
This is the armor class:
import java.util.Random;
public class Armor
{
//fields
CharacterRace charRace;
String armorName;
public int cost;
public int armorBonus;
public int armorCheckPenalty;
public int arcaneSpellFailChance;
[Code] ....
And this is the CharacterRace class enum:
public enum CharacterRace
{
HUMAN, ELF, HALFELF, HALFORC, DWARVE, GNOME, HALFLING
}//end enum
And lastly, this is what the armor test prints out:
0
0
0
true
true
true
I never get false (I should sometimes) and those 0s should be
30
30
15
What's wrong with my code?
View Replies
View Related
Oct 14, 2014
I'm having extreme troubles with my outputs not displaying the correct math. I have everything organized how I want it, it's just not giving me the correct answers.
The code is supposed prompt the user to enter an investment amount and an interest rate and display the future investment amount for years 1-30. The formula for this is:
futureInvestmentAmount = investmentAmount * (1 + monthlyInterestRate)^(numberOfYears*12)
Here is my code:
import java.util.Scanner;
public class InvestmentValue {
public static void main(String[] args) {
// prompt user to enter data
Scanner scan = new Scanner(System.in);
System.out.println("The amount invested: ");
[Code] ....
And I have to use a method to do this as it is what we are learning in class right now. A sample output as of now is:
The amount invested:
1000
Annual interest rate:
9
Years Future Value
11.0E15
21.0E27
[Code] .....
And obviously a future investment amount cannot equal infinity.
View Replies
View Related
Oct 23, 2014
I feel like the program is written correctly; however, the interactions pane in DoctorJava gives me numbers instead of letters. I am happy that the numbers it gives me is consistent, but it still bothers me and I do not know what to debug.
import java.util.Scanner;
public class Monogram {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String firstName, middleName, lastName;
int nameLength=1;
[code]...
View Replies
View Related
Oct 30, 2014
public class Check2
{
private int red;
private int green;
private int blue;
public Check2(){
red = 0;
green = 0;
blue = 0;
[Code] .....
And when i uses it in another class named "Check" it returns zeroes :
public class Check
{
public static void main(String[] args) {
Check2 obj = new Check2(125,254,12); // the toString method should return the values i gave it here . but it shows me zeroes instead.
System.out.println("the colors are " + obj.toString());
}
}
Output : the colors are (0,0,0)
View Replies
View Related
Jul 29, 2014
I want to be able to
(A) Restrict the number of output values per line to 3 numbers,
(B) Remove Duplicate lines, where the same numbers are duplicated just outputted in a different order.
(C) Count the number of outlines
(D) Add a fixed column to the outputs that has an ascending count from 1 upwards
I'm trying to achieve. The code is as follows:
package num.com.t1;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
*
*
*/
public class NumComT1 {
public static void main(String... args) {
[Code] ....
View Replies
View Related
Feb 14, 2014
I have been trying for days and nights , no compile error , but alot of NPEs error .......
This is my Test program
import java.util.*;
public class Test
{
public static void main (String[]args)
{
int totalShares = 0 ;
double totalCost = 0.0;
double totalProfitLoss = 0.0;
[Code] ....
I am expecting a output like this (Which I have error running:
Tracking of Stock : FCS
8 shares has been brought at $37.61
Total shares now 8 at total cost $300.88
33 shares has been brought at $36.31
Total shares now 41 at total cost $1499.11
17 shares has been sold at $42.67
Total shares now 24 at total cost $773.72
19 shares has been sold at $32.31
Total shares now 5 at total cost $159.83
31 shares has been brought at $33.85
Total shares now 36 at total cost $1209.18
28 shares has been brought at $36.37
Total shares now 64 at total cost $2227.54
20 shares has been brought at $35.49
Total shares now 84 at total cost $2937.34
At $36.00 per share, profit is $86.66
View Replies
View Related
Feb 7, 2015
Write a program called RomanNumeralHelper that allows a user to enter a roman numeral and then outputs the integer number value. Use a Scanner to accept command line input from the user and continually ask for a roman numeral until the user enters Q (or q) to stop. Your solution should NOT use a switch statement.
Here is sample input / output:
Enter a roman numeral [Q | q to quit]: III
>> 3
Enter a roman numeral [Q | q to quit]: IV
>> 4
Enter a roman numeral [Q | q to quit]: V
>> 5
Enter a roman numeral [Q | q to quit]: Q
Good Bye!
This is what I have so far in my code, but I cant get what the user inputs when I want it to output the number.
import java.util.Scanner;
public class RomanNumber4
{
public static void main(String[] args) {
// obtain input from command window
Scanner input = new Scanner(System.in);
[Code] ....
View Replies
View Related
Feb 2, 2015
Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.
First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.
import javax.swing.JOptionPane;
public class DigitsAndSum {
public static void main (String[] args) {
String str1;
String str2;
int int1 = 0;
int int2 = 0;
[Code] ....
View Replies
View Related
Oct 13, 2014
so far this is what i have written. The program works correctly but I need to be able to have the numbers i am entering to show up on the .txt file.
import java.util.Scanner;
import java.io.*;
public class LargestAndSmallest {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
[code].....
View Replies
View Related
Feb 25, 2015
I want to work on a project in which I have a GUI where I can choose certain variables from drop down menus. I want to use these variables to modify a few configuration files. I have looked upon internet for a few methods which can be used for the same. However, I am not sure about the method I should use. The files I want to modify consist of 10 -15 lines.
View Replies
View Related