How To Calculate And Display Win / Loss For Two Different Teams Using Boolean Function And Arrays
Jan 28, 2015
I am still new to Java and have an assignment that I am stuck on. I believe I got the boolean function correct, however I cannot figure out what to write in the main function. I have exhausted searching, and trying different loops, arrays, etc.
I am trying to write a small program that will calculate the gain and/or loss of the sale of stock. The program will ask the user for the number of shares, the purchase price and the selling price. I am pretty sure that the errors is coming from my calculations in the program.
import java.util.Scanner; public class investmentCalculator { public static void main (String[] args) { Scanner input = new Scanner(System.in); //User input for number of shares System.out.print("Enter the number of shares: "); double shares = input.nextDouble();
I was asked to write code to calculate a person's calories burned/min. This is what I got. The problem is I keep getting an error.
--------------------Configuration: <Default>-------------------- C:Program FilesJavajdk1.7.0_72CaloriesBurned.java:22: error: possible loss of precision caloriesBurnedPerMinute = 0.0175 * METS * weightInKg; ^ required: int found: double 1 error
Loss of precision? What does that mean? Do I have to change weightInKg into some other number type?
import java.util.Scanner; public class CaloriesBurned { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int runningHours, basketballHours, sleepingHours, METS, caloriesBurnedPerMinute;
Write a class named FileDisplay with the following methods:
1.) constructor: the class's constructor should take the name of a fil as an arugment. 2.) displayHead: This method should display only the first five lines of the file's contents
Here is the following code I have made so far
import java.io.*; public class FileDisplay { private String filename; public FileDisplay(String Filename) throws IOException
[Code] ....
First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in
public void displayHead() {FileWriter file=new FileWriter(Filename)}
do I make create another instance of the filewriter class to output data?
In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...
I need to do a rectangle using boolean array where true elements are the borders of the rectangle, and false elements are the inner space. I imagine that the first and last rows and columns must give the true element,
public class Functionality { public static boolean[][] rectangleArray(int n, int m){ boolean[ ][ ] matrix = new boolean[n][m]; for(int i = 0; i <matrix.length; i++){ for(int j = 0; j < matrix[i].length; j++){
I have understood my programming class up to this point and now I have been given a lab that I can't figure out for the life of me. Here what I have to do: Write a program that will call a method (called f) to calculate the following function" f(x)=(x^2)-16...this is what the output should be:
A stored function to calculate delivery charges given city and weight.
CREATE OR REPLACE FUNCTION CALCULATE_CHARGES ( CITY IN VARCHAR2 , CHARGES IN NUMBER , TOTAL IN NUMBER ) RETURN NUMBER AS BEGIN RETURN total:=city*charges; END CALCULATE_CHARGES;
I am making a gradebook program that calculates the averages of 25 students using 2D arrays in which the students have four test grades. I have figured out how to display the averages of each student in one column but I cant seem to figure out how to display the letter grade of the average into another column.
Right now my program reads from a .txt doc
Heres what I've got.
TestGradeBook.java
import java.util.*; import java.io.*; public class TestGradeBook { public static void main (String [] args ) throws IOException{ //Declarations final int ROWS = 100; final int TESTS = 4;
[Code] .....
GradeBook_Data.txt Name100100100100 // basic name and grades
As part of the instructions we are required to use loops and methods to solve to program this code. We are not allowed to use any set functions that are already built in java.The methods for intersection and difference MUST return int value.
import java.util.Scanner; public class setPractice { public static Scanner kbd; public static final int MAXSIZE = 20; public static void main(String[] args) { kbd = new Scanner(System.in);
The pay rate is php 35.00 per hour. any hours worked after 40 hours is paid at rate of 2 times the normal hourly rate. Calculate and display the Normal Pay, The overtime pay, and the total pay.
OUTPUT MUST BE:
Sample 1 :
Enter Hours Worked: 40 (Sample) Normal Pay: 1400 (Sample) Overtime Pay: 0 (Sample) Total Pay: 1400 (Sample)
Sample 2 :
Enter Hours Worked: 41 (Sample) Normal Pay: 1400 (Sample) Overtime Pay: 70 (Sample) Total Pay: 1470 (Sample)
Here is my code or something, but i cant finish it.
import java.util.Scanner; public class Workpay { public static void main(String[]args) { Scanner in = new Scanner (System.in); int hours; int normalpay = 35;
I have to write a program that calculates and displays a person's body mass index (BMI). The BMI is often used to determine whether a person with sedentary lifestyle is overweight or underweight for his or her height. A person's BMI is calaculated with the following formula:
BMI = Weight X 703/Height^2
where weight is measured in pounds and height is measured in inches. The program should display a message indicating whether the person has optimal weight, is underweight, or is overweight. A sedentary person's weight is considered optimal if his or her BMI is between 18.5 and 25. If the BMI is less than 18.5, the person is considered underweight. If the BMI value is greater than 25, the person is considered overweight.However I can't seem to get rid of these errors:
----jGRASP exec: javac BMI.java BMI.java:28: error: cannot find symbol Scanner keyboard = new Scanner(System.in); ^ symbol: class Scanner location: class BMI BMI.java:28: error: cannot find symbol
For this program I am calculating the annual costs of 5 office supplies (user input) each with a 5.7% inflation. The user inputs the cost of each object and my program must calculate and display the price of each object each year for 5 years. I already have this part. What I need is how to add the total costs of all 5 supplies per year and display each total cost. Here is the program:
import java.util.Scanner;//Using keyboard to enter data //Start of Class public class OfficeSupplyCalculator { //Start of Method public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter the first item");
[Code] .....
At the moment all I get for the grand total loop is the same number showing up 5 times. I feel like the problem is how I am declaring the grandtotalperyear variable but I'm not sure what is wrong.
Alright, so I'm having problems with lines 11 - 55. I'm trying to calculate the possible tiles the clicked unit can be moved on and display it to the player.
The field is a 9 (columns) by 5 (rows) grid. A unit with can move tiles horizontally or vertically based on its movement.
Example: (unit = o; possible tiles = x) (assuming movement of 2).
I tried to calculate movement by finding out what column the unit is in, subtracting the column it wants to go to, multiplying the difference by *-1 if the difference is less than 0. Then, doing the same with rows and adding the difference of columns to the difference of rows and comparing it to the unit's movement. Unfortunately, with my code, it seems to move in any directions.
@Override public void mouseClicked(MouseEvent e) { if (Main.cards.size() > 0) { mainloop: for (int i = 0; i < Main.cards.size(); i++) { Card c = (Card) Main.cards.get(i); int startingColumn = 0;
Write a program that will calculate the cost of a ticket order and display the receipt for the customer on the screen. There are 2 ticket prices: adult, and senior citizen. Adult seats are $4.50 and senior citizen seats are $3.50. If more than 5 senior citizen tickets are purchased, the customer gets an extra 20% off the of the ticket order. If more than 10 regular seats are purchased, the customer gets an additional 10% off the cost of the order. A customer can only place an order for one type of ticket. Output the type of ticket purchased, the number of tickets purchased, the gross cost, the amount of the discount, and the final cost of the order.
I am having errors with incaompatible varriables comparing float with doubles.
public class lab3 { static Library myLib; public static void main (String [] args) { Library myLib = new Library(); //Instance the Library class int ticketNum; //Number of Tickets
I'm trying to create a GUI application that calculates and displays the total cost for certain automotive maintenance services. The application should contain hree classes: 1) the main class that creates and displays the window; 2) a panel for the routine services and 3) a panel for the non-routine services. 2 and 3 are instantiated in 1. I'm pretty positive the error lies in the NonRoutinePanel class because when I comment it out of the main class the program runs fine. But I can't quite figure out which lines of code or methods are causing the problem.
When I try running the program I get these error messages:
Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1040) at java.awt.Container.add(Container.java:958) at javax.swing.JFrame.addImpl(JFrame.java:540) at java.awt.Container.add(Container.java:926) at JoesAutomotiveGUI.<init>(JoesAutomotiveGUI.java:38) at JoesAutomotiveGUI.main(JoesAutomotiveGUI.java:111)
Here's my code for the three classes:
import javax.swing.*; // Needed for Swing class import java.awt.*; // Needed for BorderLayout class public class RoutineMaintenancePanel extends JPanel { public final double oilChange = 26.00;// cost of oil change public final double lubeJob = 18.00;// cost of lube job
I am trying to use parallel arrays to store names and job titles, then display the name/job title combo depending on which is entered. I have always struggled with arrays, so I'm sure that's where my issue is, but I am not sure how to resolve this one. I tried to use the toString() method with the jobs to see if that would allow the job title to match to one of the titles listed, and I tried to not use the toString() method with the names to see if that would allow the name entered to match to one of the names listed in the array. Both options only display the "invalid" message no matter what I enter. What would be the best choice to use the arrays to properly display the information ....
import java.util.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JEmployeeTitle2 extends JApplet implements ActionListener { Container con = getContentPane();
I'm stuck trying to figure out why this isn't compiling.
Bumper.java:87: error: possible loss of precision myX = (Math.random()* (rightEdge-myXWidth) + myXWidth / 2); ^ required: int found: double Bumper.java:88: error: possible loss of precision myY = (Math.random()* (bottomEdge-myYWidth) + myYWidth / 2); ^ required: int found: double
The authenticatedUser and menu attributes are gone. I never know when it's going to happen so I can't trace it. Any guesses why those type session objects would die?
I attached an image of what menu object looks like.
public void draw(ArrayList<int[]> good,ArrayList<int[]> bad){ drawing = true; goodToDraw=good; badToDraw=bad; System.out.println("Canvase/draw: Calling paint with a size of "+goodToDraw.size()); middleMan();
[code]....
What this does is two ArrayList are sent to the draw function.one called good and the other bad. Right now I am only working on good. What is suppose to happen is paint takes all the good coordinates and paints them but I seem to loose the arrayList size when repaint is called. You can see in the picture below of my console that it starts of with 20. Then because I was wondering if the scope was to short i called middleman to make sure that it held its size outside of the first function. Then finally it calls paint and tells me the array is empty. To simplefy..Why does my arraylist size go to zero when I call repaint?
I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.
[ public class Array1 { public static void main(String[] args) { int array [ ] = new int[100]; for (int i = 0; i < array.length; i++) { array[i] = (int) (Math.random() * 26);
I'm struggling with inheritance in my assignment. The assignment states that I should use the calculatePrice() to calculate the total price and use another method to display the total. The I must overload the calculatePrice() and add a fee in the SpeedOrder() class.
My main class
package useorder; import javax.swing.*; public class UseOrder { /** * @param args the command line arguments */ public static void main(String[] args) { Order.display();
[Code] .....
The problem is mainly displaying the TotalPrice field and. I can't display TotalPrice if it's not static but if it's static I can't inherit it to the SpeedOrder class to assign the total in the overloaded calculateprice method. How can I display the total in my order class and use it in my SpeedOrder class?