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;
class first { public static void main(String []args) { System.out.println(args[0]+" "+args[1]+" "+args[3]+" "+args[4]); int dec = 267; int hex = 0x10B; int oct = 0413; int bin = 0b100001011; System.out.println("Octal + Binary : "+oct+bin); System.out.println("HexaDecimal + Decimal : "+dec+hex); } }
i want add two variables in print method.... how should i use the concatenate operator for the same.
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,
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.
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;
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);
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;
New to java/programming and i cant understand why the pen variable does not display the the correct value ... For example for input 1 ; 2 ; 3 ; 4 both variables will display 10 and i dont understand why pen does not have the value 6 .
import acm.program.*; public class Chap4_ex12 extends ConsoleProgram { public void run () { int pen = 0; int r = 1; int sum = 0; while (r !=SANTINEL) { r = readInt(" ? "); pen=sum ;
Variables defined in interface are public static and final so I was thinking that we should not be able to override the variables in a class thats implementing the interface. But when I am compiling the below class, it compiles fine and gives the correct values. but when I did disp.abhi = 35; it gives a compile error (cannot override final variable)
interface display{ int abhi = 10; void displayName();
This is my first time working with C++ and I have put together this program and came up with two errors and I am unsure what it is wanting me to do. The errors I got are:
1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(30): error C2064: term does not evaluate to a function taking 1 arguments 1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(38): error C2064: term does not evaluate to a function taking 1 arguments
#include<iostream> using std::cin; using std::cout; using std::endl; //initialize arrays int incr10(int* numa,int* numb);
I am new in this programming language, java. I have a problem after I set my path ";C:Program Files (x86)Javajdk1.7.0_51in". I made a simple program but an error occurred. Here's the screenshot.....
I continuously get an error for lines 34, 36, and 37 saying that the variables may not have been initialized.
import java.util.Scanner; import java.util.Random; public class MathTutor { public static void main(String[] args) { Random r = new Random (); Scanner input = new Scanner (System.in); /*int min=1; int max=10;*/ int num1,num2,operation; int n1= r.nextInt((9+1)+1); int n2= r.nextInt((9+1)+1); operation= r.nextInt(3); int correctAnswer; int userAnswer;
Let's say within a class I create a method that takes care of creating a java swing layout with labels, buttons etc.. then attach an action listener (inner class) for each button to change a respective label text. All I would need is that the action listener method can access and modify the label as needed.
Have read about static, protected, private, getters and setters but honestly bit confused about which structure should be adopted as a best practice. Global static protected variables for the labels along with private inner classes implementing ActionListeners believe will do the trick and will be able to access the labels but not convinced this is good practice.
you can also refer this link Local variables in java?Local variables in java?To meet temporary requirements of the programmers some times..we have to create variables inside method or bock or constructor such type of variables are called as Local Variables.
----> Local variables also known as stack variables or automatic variables or temporary variables
----> Local variables will be stored inside Stack.
-----> The local variables will be created while executing the block
in which we declared it and destroyed once the block completed. Hence the scope of local variables is exactly same as the block in which we declared it.
package com.javatask.in; class A{ public static void main(String args[]){ int i=0; // Local variable
Is there any way to save variables while I'm using applet as single runnable .jar file?
For example if I start app first time some variable has value of 100. While using app it changes to 200. After closing app it disapear and next run gives me 100 again instead of 200. Is there any way to save that 200?
I will like to add to the questions about constructors and its this. I have a class A with a constructor, i have a class B which initialize the constructor. also i have a class C which needs a variable in class A but doesn't need to initialize the constructor of A. the question how do i access the variable of class A without initializing the constructor.
Does a variable have public access modifier? if we can use it within the class and outside of the class then can i access a public variable as follows??
class mo { void display() { public int a=9; System.out.println(a); } public static void main(String[] args) { mo m=new mo(); m.display(); } }
ERROR: It shows 6 errors :-O. Error 1. illegal start of the expression 2. class,interface, or enum expected
I'm having some trouble figuring out how to change the value of a variable that is passed into a class. I've tried just changing the variable, I've tried changing it by using the this.variable command, and I've even tried calling the setter class from within the class to change it, but it's still not working right. The first class is the one with Main in it and I just feed it some dummy data:
public class ExamConverter { public static void main(String[] args) { // TODO Auto-generated method stub Age testAge = new Age();
[Code] .....
This is the other class to calculate the age the way we do it on psych tests - it might not be mathematically accurate, but it's what all the tables and such for raw to scaled score conversion are based on, so the math needs to be the same as opposed to "accurate" because of some months having 30 or 31 days, etc.
public class Age { //==================Properties================== // Variables for the test date and client date of birth private int TestMonth; private int TestDay; private int TestYear; private int ClientMonth; private int ClientDay; private int ClientYear;
[Code] ......
Based on this dummy data, the output is: Test: 5/4/2014 DOB: 5/5/1971 Age Years: 43 Months: 0 Days: 0
However, it should be: Test: 5/4/2014 DOB: 5/5/1971 Age Years: 42 Months: 11 Days: 29