JGRASP Won't Allow To Declare Variables As Strings
Oct 10, 2014
Java Code:
import java.util.Scanner;//Imports Scanner
public class operadoreslogicos//imports a public class {
public static void main (String [] args)//defines the state of a class {
Scanner input = new Scanner (System.in);//Inputs a scanner to read user
//keyboard
boolean cierto = true,// Declares variables as boolean and applies a value
[Code] .....
The word string is supposed to turn purple when I type it, but it just stays normal, so it doesn't declare hello and bye as variables.
View Replies
ADVERTISEMENT
May 27, 2015
Write a program that declares and concatenates various strings. Declare strings for your first name, middle initial and last name, along with one for your address, city, state and zip. Make an additional string called firstLine, which will be a concatenation of first name, space, middle initial, period, space, and last name. Assign each of these strings a value, and then print the information in the following format:
First Line (First name Middle initial (period) Last name)
Address
City, State
Zip
For example:
John Q. Public
1234 Any Street
Cleveland, Ohio
44101
Now reassign the strings in the same program (Do not create a separately compiled program!) and repeat the printout for different information. When you are finished, your program will print out two groups as above.
The information should be placed into the seven separate strings, then a first line should be formed by concatenating first name, space, middle initial, period, space, and last name. The city and state line should be formed by printing city followed by a comma, a space, then the state (NOT by concatenation). This is so you can see different ways of making lines."
And this is what I have so far:
View Replies
View Related
Feb 14, 2015
The problem is to figure out the number of cartons needed to box up the strawberries picked by the farmer and his wife. The farmer picks 8.4 lbs per hour and the wife pick 10.8 pounds per hour. They pick from 8 am until 4Pm (8 hours). You can put 20 pounds per box.I understand the word problem and how to declare and initialize variables. I'm just confused how to display the math into java to solve it.
View Replies
View Related
Mar 26, 2012
Any way of How to declare an ArrayList that can hold int variables?
View Replies
View Related
Sep 6, 2014
Where usually to instantiate and declare variables to be used in a loop. If you declare it outside to be used in the loop it will still be there when the loop is done, never to be used again and is just sitting there taking up memory. However, if you declare it inside the loop, you have the issue of it constantly creating space for said variable, but once it's out of scope it's gone. Is there any advantage performance wise to doing it either way?
View Replies
View Related
Oct 3, 2014
Write a program OutCircle.java that declares and initializes three floating-point variables (r, x, y): the first variable represents the radius r of a circle centered at (0,0) and the second and third variables are the coordinates (x, y) of a point in the plane.Your program should print true if the point is outside the circle and false otherwise. Hint: A point is outside the circle when its distance to the center is greater than the radius.
View Replies
View Related
May 12, 2014
I'm done with my project and I'm not trying to make it into a jar with JGrasp... I start by making a project then I click the option to make my project into a jar... Everything works but when I try to run it it says that the main class cannot be found... How can I fix this?
View Replies
View Related
Oct 7, 2014
I'm currently taking a Java Programming module in college, the program we are using is jGrasp and I'm currently stuck on one aspect of the language.
I did VB last year and I enjoyed it and got good grades so I'm comfortable with Java in terms of compiling the code correctly and getting it to run with no errors.
But for a project we got yesterday, the user must be able to enter data (e.g. an answer) into jGrasp without using a GUI. This is the case because we won't be dealing with GUIs until next semester.
I'm able to handle the rest of the project, but the part which I can't figure out is how the user can interact with jGrasp without the aid of a GUI.
View Replies
View Related
Oct 10, 2014
Basically, I have want to keep typing numbers and pressing enter and the same program keeps repeating itself. This is the code I need to repeat,
import java.util.Scanner;
class Averagecalc2 {
public static void main(String args []) {
Scanner input = new Scanner(System.in);
double num,
[Code] .....
View Replies
View Related
May 1, 2014
So I downloaded jgrasp and eclipse on a new computer and am trying to figure out how their filing/path system works.In eclipse I created a new project under which I've imported all my files for my comp sci class, so they're all under this one project which is my only project. I attached a pic of what my eclipse workspace looks like. In this project folder is a file I'm trying to run.
I keep getting an error saying "editor" does not contain a main type.When I change my class name to the project folder I end up getting an option to run the program as an applet or an application, but either one I choose I get the same error message. In the bottom it gives me a warning saying
DescriptionResourcePathLocationType
Build path specifies execution environment CDC-1.1/Foundation-1.1. There are no JREs installed in the workspace that are strictly compatible with this environment. CS1050AssignmentsBuild pathJRE System Library Problem
I tried running the program in jgrasp and got this error
----jGRASP wedge2 error: command "javac" not found.
---- This command must be in the current working directory or
---- on the current system PATH or jGRASP PATH to use this function.
---- System + jGRASP PATH is "C:UsersQudrat.MommandiDocuments;C:Windowssystem32;C:Program Files (x86)InteliCLS Client;C:Progra
[code]...
I have the JDK installed in program files, I have the correct versions of eclipse and Jgrasp, and have uninstalled / reinstalled the JDK/Jgrasp/Eclipse so I don't know what the problem is?
View Replies
View Related
Feb 3, 2015
I keep getting the error Admit.java:10 cannot find symbol
import java.util.*;
public class Admit {
public static void main(String[] args) {
sayIntro();
Scanner console = new Scanner(System.in);
System.out.println("Information for applicant #1:");
getScore(console);
getGPA(console);
[Code] ....
The compiler then reads:
Admit.java:10: error: cannot find symbol
score1(ACTScore, SATScore, GPAScore);
^
symbol: variable ACTScore
location: class Admit
Admit.java:10: error: cannot find symbol
[Code] .....
10 errors
View Replies
View Related
Sep 6, 2014
We're learning printf with JGrasp as the environment at the moment. Heres the problem.
I have a string as this:
String header1 = new String ("Caswell Catering and Convention Service");
as for the printf line, its this:
System.out.printf ("%-5s/n", header 1);
The output is right justified no matter the use of the "-" or without and I can't seem to find the correct thing to do to make it left justified.
View Replies
View Related
Aug 25, 2014
I am having an array of strings and i want to find out whether these strings contained in the array contain a similar character or not.For example i am having following strings in the array of string:
aadafbd
dsfgdfbvc
sdfgyub
fhjgbjhjd
my program should provide following result: 3 because i have 3 characters which are similar in all the strings of the array(f,b,d).
View Replies
View Related
Mar 4, 2015
Write a program named QuadraticTable.java that takes three double arguments and two int arguments (in that order) from the command line. The three doubles will represent a, b, and c from the quadratic formula.
If the discriminant is non-negative, find and print the solutions to the quadratic equation. (The plus/minus sign in the quadratic formula indicates that you would separately perform both operations). Otherwise print "no real solutions".
Then using the last two int arguments as x_min and x_max, print a table of x and ax
2 + bx + c
values using the a, b, and c read in as command line arguments.
Sample output: (command line arguments were 1 0 2 -3 3)
1x^2 + 0x + 2 has no real solutions.
X 1x^2 + 0x + 2
-3 11
-2 6
-1 2
0 2
1 3
2 6
3 11
View Replies
View Related
Sep 30, 2014
I have been trying to get this code to work but in jGrasp it give the no main method, applet, or IMDlet. The assignment states: Design a class Message that models an e-mail message. A message has a recipient, a sender, and a message text. Support the following methods:
-A constructor that takes the sender and recipient
-A method append that appends a line of text to the message body a method toString that makes the message into one long string like this:
"From:Harry Morgan
To: Rudolf Reindeer. . ."
Write a program that uses this class to make a message and print it. package emailmodel;
import java.util.Scanner;
public class Message
{
private String senderemail;
private String receiveremail;
[code]....
View Replies
View Related
Sep 13, 2014
The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets: box, sideline, premium, and general admission. After each game, the data is stored in a file in the following format:
ticketPrice numberOfTicketsSold
Sample data might look like:
250 5750
100 28000
50 35750
25 18750
The first line indicates that the box ticket price is $250 and that 5750 tickets were sold at that price.
Your program should input in this data (using Scanner or an input dialog box), then output that data to a message dialog box along with total ticket sales information. Output the total number of tickets sold and the total sale amount. Make your output user-friendly and "pretty". Format your output with two decimal places. Use JOptionPane and the formatting techniques learned in chapter 3 for your output. Example output might be:
5750 Box Tickets sold at $250.00
28000 Sideline Tickets sold at $100.00
35750 Premium Tickets sold at $50.00
18750 General Admission tickets sold at $25.00
View Replies
View Related
Sep 19, 2014
Here is the objective of the assignment:
Quote : A bank in your town updates its customers' account at the end of each month. The bank offers two types of accounts: savings and checking. Every customer must maintain a minimum balance. If a customer's balance falls below the minimum, there is a service charge of $10 for savings accounts and $25 for checking accounts. If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:
- Savings accounts receive 4% interest.
- Checking accounts with balances of up to $5000 more than the minimum balance receive 3% interest; otherwise, the interest is 5%.
Write a program that reads a customer's account number (integer), account type (character: s for savings or c for checking), minimum balance that the account should maintain, and the current balance. The program should then output the account number, account type, current balance, and an appropriate message.
Your program should only allow 'c', 'C', 's', or 'S' as valid input, any other character for the account type should result in an error message. Format your monetary output to two decimal places, and use constants for all the above constant values.
Sample output:
Please enter your account number (int), account type (char), minimum balance, and current balance:
46728 S 1000 2700
Account Number: 46728
Account Type: S
You have earned 0.04 interest on your account.
Current Balance: $2808.00
[Code] .....
Invalid account type!
View Replies
View Related
Mar 26, 2014
I can sort strings in a collection by uppercase and then lowercase though I was wondering if there is any way of doing it in reverse, sorting by lowercase then by uppercase.
View Replies
View Related
Mar 29, 2015
Is it possible to declare a counter with a value outside of a for loop?
I have a counter that will end prematurely in a while loop during various iterations and I want to pick it back up in a catch all for loop at the end
Let's say I have a while loop
while(something) {
total++
}
then after I have a for loop that I want to start at total but would rather do that then make a new counter variable.
for(total;total < 20;total++)
Is something like this possible or is this a horrible thing to want anyways?
View Replies
View Related
Jun 5, 2014
I have a jtable which i want to put an array into... and Really don't know how.. I dont want to use array list mainly because it looks way to complicated so there must be some other way using defaultablemodel but i dont know how..
So here's my code: just a snippet which includes the testing of the jtable
String[] columns = {"col1", "col2", "col3", "col4", "col5", "col6"};
//declare 2d array
String[] [] data = {{"1", "2", "3", "4", "5", "6"}};
jt = new JTable (data, columns);
jt.setPreferredScrollableViewportSize (new Dimension (50, 80));
//set initial selectibility to false
jt.setFocusable (false);
jt.setRowSelectionAllowed (false);
JScrollPane tableContainer = new JScrollPane (jt);
frame.getContentPane ().add (tableContainer);
View Replies
View Related
Apr 16, 2015
1.How to declare array in java?
2.How to push elements in it in key-value value pair in java?
For example-
This is the way i do it in javascript..
I want to do like this in java..
var my_array;
for(var i = 0; i<5; i++)
{
my_array.push({x: i, y:0});
}
where,push is builtin method in javascript.
View Replies
View Related
Oct 28, 2014
I want to declare a 2 dimensional array in java which has 3 column and unlimited number of rows, i want to give a special name to each column . The type of first column is string second one is int and the last one is string
Column1_name
Column2_name
Column3_name
String value
Int value
String value
.
.
.
.
.
.
View Replies
View Related
Aug 3, 2014
I mean i need to access to two txt file at the same time so i did this in method:
DataInputStream din= new DataInputStream(FileInputStream("vip.txt"));
DataInputStream din2= new DataInputStream(FileInputStream("corporate.txt"));
But there are errors when i compile and they pointing to these two lines.
View Replies
View Related
Apr 26, 2015
I'm trying to code a little text RPG. I've made a little "personality test", with 4 questions (answers a b c), where every letter stands for a type of personality. The analysis of the result is simple counting of the answers, if you have 3 answers a (4 questions), then a has won. If 2 on a, and 2 on b, a simple Random method shows weather result a or b.
Now... the test should give you a "partner" (imagine the pokemon game with 3 different starter pokemon). I have now 3 string variables, like 3 different partners. They are all declared somewhere outside, but i only need one later.
Like...the test is completed, you have your partner and how can i make now that the program is just showing me my partner? Like...when i type " System.out.println(partner); " (outside of the test loop! ) that i only get the one i got through the test?
I was trying to declare in every loop the partner String with every result. But outside the loop java isn't recognising that String, bcs...ofc...it was declared for the loop. So i had in every if or else if clause a " String partner = anwsA;" and answB and answC, thats why i cant declare them outside.
Short: i need a partner String variable that could have 3 possible results... i jut need one
I'm using Eclipse Luna 4.4
View Replies
View Related
Feb 10, 2014
Still trying to get a handle on arrays! So, I declare an array to be a 46x1 and I am trying to populate it with a Log formula that I am using but I keep getting an ArrayIndexOutofBoundsException.
Code :
private double[][] LNValues = new double[46][1];
//Calculating y=LN(E-k) and Initializing the Array
for(int x=0; x<LNValues.length; x++)
{
double i = Math.log(eValues[x][1] - kValue);
if(i > 0)
[Code] ....
View Replies
View Related
Jul 16, 2014
2. Declare a class called Quadrilateral that can be used to represent a quadrilateral. What instance variables are required? This class should include the following methods:
• Accessor and mutator methods. Notice that negative and zero lengths should not be accepted.
• A method called isParallelogram that returns a Boolean value indicating if the quadrilateral is a parallelogram.
• A method called isRectangle that indicates if the quadrilateral is a rectangle. This method should invoke the method isParallelogram and return a Boolean value.
• A method called isSquare that returns the Boolean value “true” if the quadrilateral is a square. This method should invoke the method isRectangle and return a Boolean value. URL...
import java.awt.Point;
public class Quadrilateral{
private Point p1, p2, p3, p4;
public Quadrilateral (Point p1, Point p2, Point p3, Point p4) {
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
this.p4 = p4;
}
}
that is all i got, my professor has never mentioned on anything about quadrilateral,and i have 0 knowledge about this.
View Replies
View Related