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;
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,
Right now I have three stacks. Each stack holds characters, with the normal operations of pushing and popping. I am trying to compare two characters from stack1 and stack2(each character is a digit character). I would like to be able to do arithmetic on the digit characters and the push the answer on to a result stack.
Ex.) I pop character '3' from stack1 and '5' from stack2. Then I add the two. equaling '8' and pushing that character on to the result stack. This will hopefully in turn allow me to add arbitrary large numbers that integers will not support.
I am having trouble because I believe I am getting some ascii character values when I pop off the result stack. here is a small piece of my code
public void addition() { char temp1 ,temp2; int i = s1.getSize(); for(int j= 0;j<i;j++) { temp1 = s1.pop(); temp2 = s2.pop(); if(temp1+temp2>=10)
String a = "***************"; for(int i = 0; i++; i<10){
System.out.println(a); a = a - "*"; }
I searched about this online and read strings are unmutable in java but what does that exactly mean ? If the string cannot be changed how i am able to add the characters but not remove them.
I am making a java text adventure and i am trying to add characters to it. I wrote it exactly the same as i wrote the items class (which works fine) but for some reason the character class keeps getting a null pointer exception when it gets to line 140 in the room class
characters.add(c); game class import java.util.ArrayList; import java.util.HashMap; /** * Game class for Free Willy Five: an exciting text based adventure game. *
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;
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:
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.
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()); } }
(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) {
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
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;
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);
I want to remove all numeric number in String text
String text = She was born in 1964,and now her age is 55; String delim = ","; StringTokenizer stringTok = new StringTokenizer(text, delim); String f1 = "%-40s"; String h1 = String.format(f1, "Token list");
I am using a TreeSet to tokenize a string. The output is sorted with numeric first followed by words
E.g. 13 26 45 and before etc.....................
Is there a tidy way to remove the numeric?
Last bit of my code is :-
// print the words separating them with a space for(String word : words) { System.out.print(word + " "); } } catch (FileNotFoundException fnfe) { System.err.println("Cannot read the input file - pass a valid file name"); }
I am trying to sort a JTable on an all numeric (integer) column. From what I read, if the sorter knows the type is integer it should sort correctly. This is my code:
public class ActorTableModel extends DefaultTableModel { private static final long serialVersionUID = 1005352603826663105L; public ActorTableModel (Object data[][],Object columnNames[]) { super(data,columnNames); } public Class<?> getColumnClass (int column) { if (column==0) { return(Integer.class); } return(String.class); } }
The result is when I sort on that column (0), it sorts alphabetically not numerically.
I am trying to write out a program that takes numerical input from the user and converts it to a date using the English month name. I am experimenting with the method of a "switch" statement without using the "break" clause. However, I seem to be missing something, as Eclipse is telling me I have a syntax error with my block. My curly braces seem properly placed. Also, I made sure to follow guidelines to make my code fit on the screen and remain easy to read.
import acm.program.*; public class MethodsThatReturnNonNumericValues extends ConsoleProgram { public void run() { int month=readInt("Enter month number"); int day=readInt("Enter day"); int year=readInt("Enter year");
At first I wanted to just use an array and set each day a value, however I was told that it has to be stored as a string.
Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:
A. Set the day. B. Print the day. C. Return the day. D. Return the next day. E. Return the previous day. F. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add four days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday. G. Add the appropriate constructors. H. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G. I. Write a program to test various operations on the class Day.
import java.util.*; public class Day { static Scanner readinput = new Scanner(System.in); String day; public Day(String day) {
[Code] ....
So right now if I run my code it allows me to type in a day, then it gives me the next and previous day, the last part is to add X days to it. Ideally I would like to be able to take the day entered, depending on the day set a numeric value, then add prompt for number of days you want to add. The program should then use modal (%7 ) to add value to the value that was given based on the day, and then translate it back into a String value (the day).
I am trying to read numeric values from a text file into an array. This is what i have so far but when i compile it, it doesn't run and give me a result.
import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class question2_17110538 {
So I have to convert strings to double numbers and there can be no exception.
The strings that aren't numbers or do not fit into a set criteria have to be discarded.
When I try to write this I get an exception when a non-numeric is entered and the code stops.
What can I do? Also, am I finding the average of the array correctly?
import java.util.*; public class Grades{ public static void main(String args[]){ int arraycount = 0; final int SIZE = 10; int validArraycount = 0; final int ValidArraySize = 10;
I have a problem about this numeric or value error on my java class. Whenever I am calling for the procedure in callable statement it says that error. I don't know what is the problem with my sql code because I;ve tried running it on database alone and it runs perfectly. The results that I need came out fine. But when I'm already calling it in java that error appears. But I tried on finding the line that the said error is coming from and here is the code...
create or replace PROCEDURE RENTING (P_NNAME IN VARCHAR2, P_ADD IN VARCHAR2, P_PHONE IN NUMBER,
In the test program, you will need to convert the Strings for quantity and price to numeric types. To do this, you could use the Integer.parseInt() method and the Double.parseDouble() methods. I'm not sure what he means by that. I attempted it in my program but I get these errors
Exception in thread "main" java.lang.Error: Unresolved compilation problems: number cannot be resolved to a variable description cannot be resolved to a variable quantity cannot be resolved to a variable price cannot be resolved to a variable Duplicate local variable quantity Duplicate local variable price Syntax error on token "myInvoice", delete this token The method getinvoiceAmount() is undefined for the type String
at InvoiceTest.main(InvoiceTest.java:7)
Code:
public class Invoice { private String number; //Instance variables private String description;//Instance variables private int quantity;//Instance variables private double price;//Instance variables
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;
I have a string value returned from a background tool that will range from 0 to possibly terabytes as a full number. I want to format that number to use commas and to reduce the character count using an appropriate size modifier (KiB, MiB, GiB, etc). I've tried converting the string number to a Double value using Double.parseDouble() and then performing the math based on the size of the value with this code: