Create a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle. To do this you will need to write a Rectangle class and a separate runner class. Your program should include instance variables, constructors, an area method, a perimeter method, a toString method, accessor and mutator methods, and user input. Your runner class should include 3 Rectangle objects. One default rectangle, one coded rectangle, and one user input rectangle. All methods should be tested in the runner class.
This is my code:
import java.util.Scanner; public class Rectangle { double length; double width; public Rectangle() {
[Code] ...
What have I done??? I have created this program using the few different resources with which I am supplied, but I don't understand the resources.
This program is for a swimming pool filling service company. They charge 2 cents per gallon and $50 per hour to fill a pool. The truck can fill at a rate of 730 gallons per hour.
Create the Pool class that calculates the cost to fill a pool based on it's Shape, length, width and depth. (Input order is S L W D)
The pool class will need data fields for String shape, double length, double width, double depth, static double GallonsPerSqFoot = 7.4805, static double price per gallon = .02, static double FillingFeePerHour = 50.0, and static double FillingRate = 730gal/hr.
Create a No-Arg constructor and a constructor that accepts the non-static values, and has the methods: getShape, getLength, getWidth, getDepth, getGallons, getHours, getFillingFeePerHour, getHourlyCost and getTotalCost.
At the end of the class, create a main() method that asks for the input and returns the output based on the Pool class gets.. methods.
The shape options are oblong or rectangle. (A round pool would be oblong with the same width and height, a square pool would have the same width and height)
Example Output An oblong pool 18.00 feet long by 12.00 feet wide and 5.00 feet deep will use 6923.10 gallons of water and take 9.48 hours to fill. The total cost will be 612.65.
while (gamesPlayed<gameQty) { userChoice = JOptionPane.showInputDialog("Rock, Paper, or Scissors?"); //Determine winner for each game if (compChoice.equalsIgnoreCase(userChoice));
[Code] ....
It seems to circle through the loop gameQty times, without comparing.
In my JSP I need to retrieve some data from MySQL. I need to assign a "email" variable to the "WHERE" clause. The variable is retrieved from the session attribute. So far, I have this code:
<sql:query dataSource="${user}" var="result"> SELECT * from users where email = ${sessionScope.email}; </sql:query>
import java.util.Scanner; public class Try{ static String name; static int age; static Scanner a = new Scanner(System.in); static Scanner b = new Scanner(System.in); static Scanner c = new Scanner(System.in); public Try(String name, int age){
[Code] ....
I was trying to make a program that asks the user to create a person or a group of persons and assign names and age to them. So I made a constractor "Try" and a method "AskUser".in AskUser() I use a do/while loop where user is asked to input a name, an age and if he likes to create another person. Now how do I take the input data each time the loop runs, and send it to constractor to create new objects with it? And how these new objects will be called?
I am able to get output from my constructor when I place a loop inside of it. However when I try to access the private variable that I thought was set by the constructor I get nothing. When I check its size it is zero as well.
Java Code:
public class WinningHand extends PokerCalculator { private int p1Size; private int p2Size; private String[] p1Hand = new String[p1Size]; private String[] p2Hand = new String[p2Size];
I have a program that using one JFrame which opens one of two JDialog windows depending on which button is pressed.
How do I assign listeners to the buttons and fields on the JDialog window? I added listeners on the View end, but how do I process them? I tried adding the '..implements ActionListener" class in the main Controller but it does not recognize/hear anything.
I have been asked to write a library program that will keep record of books and the year it was published. The program should ask the user how many rows he wants accept the string input from the user and display them in rows and columns. This is how i code it
package multidimension; import java.util.Scanner; public class bookrecords { public static void main(String[]args){ //declaring a scanner variable Scanner input =new Scanner(System.in);
I have a txtfile which I read and go through. My question is what are the ways I could do to read a txtfile of words and assign an empty score to each of the word in it. So each word will have a 0 value. Later on I will manipulate the score but for now I want each word to have a 0 score.What I have at the moment is reading a text file full of words eg:
private void readtextfile() { try { Scanner rd = new Scanner( new File("filename")); List<String> lines = new ArrayList<String>(); while (sc.hasNextLine()) { lines.add(sc.nextLine());
[code]...
how to make each of the words to have a score of zero 0?
byte b = 100; it works (implicit conversion of implicit int literal 100 to byte.
But if you have a methodvoid bla(byte b){}
And want to invoke it with a literal (which is an int by default):bla(8) then there is no implicit conversion.
Is the byte b = 100; just an exception in Java? And is it the rule that one has to explicitely cast (narrow) integer literals when passing to smaller-than-int types?
I am looping through data in Android, using Parse data. I came up with this as a way to get user information; the larger goal is to create a model of data that I can use in an array adapter, so I can create a custom list view (as described here [URL] .... In the example, the data are hard-coded, not pulled from a database.
public static ArrayList<Midwifefirm> getUsers() { //Parse data to get users ParseQuery<ParseUser> query = ParseUser.getQuery(); query.orderByAscending(ParseConstants.KEY_PRACTICE_NAME); query.findInBackground(new FindCallback<ParseUser>() {
[Code] ....
The intention is that for every user that does not have the type patient, collect this data about them, then store it in the arrayList.
On the return statement, though, there is an error: cannot return a value from a method with a void return type.
I may be over complicating this...read through various sources to get a model for this...in the end, I want to display a list of information about specific users, after the user makes a selection of a city...it would therefore display all the information about the medical practices in that city.
JScrollPane scrollPane = new JScrollPane(); contentPanel.add(scrollPane, BorderLayout.CENTER); tbl = new JXTable(); tbl.setColumnSelectionAllowed(true); tbl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tbl.setEditable(false); scrollPane.setViewportView(tbl);
The problem is that when it gets filled, all the columns are squashed together to fit into the jxtable. I expected the columns to be adjusted according to the width of the column header or column value (which ever is wider) and then for a horizontal scroll bar to be displayed that will enable me to scroll left or right.
how to set the columnwidth in csv file using javacode.
I used FileWriter class to upload data into the csv file but csv file is taking default width while showing content. Is there a way to set the fixed column width or set width dinamically based on value?
Returning true from getScrollableTracksViewportWidth() makes the table (or other Scrollable) size its width to match the viewport. I need the opposite: for the viewport to expand its width to accommodate the table (of course, limited by the constraints imposed by the scroll pane's container's layout manager) without reducing column widths i.e. setAutoResizeMode(AUTO_RESIZE_OFF).
I have achieved this by overriding
getPreferredScrollableViewportSize(): JTable table = new JTable() { @Override public Dimension getPreferredScrollableViewportSize() { return new Dimension(super.getPreferredSize().width, super.getPreferredScrollableViewportSize().height); } };
Now when the scroll pane is added at BorderLayout.CENTER and the frame is pack()ed, all columns of the table are displayed, without need for a horizontal scrollbar.
I was suppose to create a simple Java program for calculating the area of a rectangle (height * width). Then check the user’s input, and make sure that they enter in a positive integer, and letting them try again if they enter in a negative number. (I'm not sure how to get them to try again.
I am suppose to use an "if" statements and indeterminate loops to achieve the solution. The program will have the following requirements:
1. Ask the user to enter in both a height and width (as an integer) 2. If the user enters in a negative number, display an error 3. If the user enters in a negative number, give them another chance to enter in the correct value 4. Calculate the area and display to the screen once two positive integers have been entered.
import java.util.Scanner; public class RectangleAreaCalc { public static void main(String[] args) { int length; int width; int area;
Any way to get my Java window to open with a certain width and height. I've been googling and haven't found to much valuable information. Here is what I have so far.
import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class JavaWindow{ //Bring up the frame. private JFrame f = new JFrame("JavaWindow");
[Code] ....
When you compile that it runs a small window. I would like that window to be bigger when the file opens.
I have a ComboBox -- just a simple ComboBox with string items.
My string items aren't very long (5 letters max), but the ComboBox shows quite wide relative to my strings. So I would like to size my ComboBox to the size of my strings.
I messed around with setting the CellFactory of the ComboBox, and have the Cells produced by the CellFactory set the preferred width of the cells to some constant like 100. That worked in terms of changing the size of the ComboBox to the preferred width of 100.
But what I really want to do is to compute the preferred width from the string items. For that I need to be able to compute how wide a string item will be when rendered. And I guess that depends on the font size used by the ComboBox to render strings, which probably depends on the platform (OS X different to Windows?).
I am developing a JavaFX application under Java 8 on my Ubuntu 14.04 (32 bit) system. When I run it on the Ubuntu box, all is fine, but when I run it under Windows 7 Home Premium (64 bit) with the same Java8 release installed, all my buttons have their text ellipsised (sp?). Why the behavior is different? Or is this a bug in JavaFX? Here are the particulars:
I'm using the tableview-component. The size of font of header is greater then that of cells. The problem is: the width of the column bases on the cell with the longest string and if the header-string is longer then the header gets truncated (it shows ellipsis) and I have to change the width of column manually. How could I solve this problem? The easiest way would be to compute the column-width on myself. I can't find any method in javafx, that would allow to compute the width of string in pixels. In Swing there is the FontMetrics class and Graphics class, so it is easy to get the width in pixels. Are there any pendants to this classes in JavaFX?