How To Calculate Total Age In Months And Store As Variable

Feb 9, 2015

I was wondering how can I calculate total age in months and store it as variable? this is what I have so far:

*
* You will ask the user to provide their name (as a single word, assume first name here)
* You will ask the user their age in full years (no fraction or months)
* You will ask the user how many full months since their last birthday (again, whole numbers here).
*
* You will use this information to calculate the user's age in months and use that information to print out a greeting.
*/
import java.util.Scanner;

[code].....

View Replies


ADVERTISEMENT

Program To Store Total Rainfall For Each Of 12 Months Into Array Of Doubles

Oct 26, 2014

"Create a project called RainFall and a class nameD RainFall. Write a program that stores the total rainfall for each of 12 months into an array of doubles. The program should display total rainfall for the year, the average monthly rainfall, the month with the most rain and the month with the least rain. When outputting the month with the most and least rain, output the name of the month. This is what I have so far.

Scanner keyboard = new Scanner(System.in);
double averageMonthly;
double mostRain;
double leastRain;
int months;
double monthlyRain = 0;
double totalRain = 0;

[Code] ....

View Replies View Related

Create Array / Store 5 Objects And Calculate Total Price - VAT Rate

May 6, 2014

How can I do the work below in Java

In this main class, create 5 objects of the class Menu, as defined in the table below.

Name amount of calories cooking time price per person number of drinks

Fufu and Groundnut Soup 564.65 2515.572
Red Red 345 12 9.980
Rice and Beef Stew 560.4 1512.651
Ga Kenkey and Fish 780 10 10.15 1
Banku and Tilapia 450.4 35 25.17 2

Exercise d
In your main class create an array of length 5, and store the 5 objects (Exercise c) into the array. You can use any name for your array.

From the array, use a loop to: Print the details of all the objects using the method you defined in Exercise b.

Exercise e
Use another loop to:
-Print only the name and cooking time of all the dishes that take less than 30 minutes to cook. Hint: you may use the getter methods for the name and cooking time attributes, and then, print these values (name, cooking time).

Exercise f
Use another loop to :
-Calculate and print the total price of all the objects (in the array).
-Calculate the total price of all the objects with VAT included for each dish (VAT rate is 17.5%).

Submission
-Create a folder with your index number as its name.
-Copy your Java Project folder into the created folder.
-Print a hard copy of your classes.
-Submit both soft copy and hard copy of your project

View Replies View Related

A Program That Stores Total Rainfall For Each Of 12 Months

Apr 29, 2015

Write a program that stores the total rainfall for each of the 12 months into an array of doubles. The program should have methods that return the following:

The total rainfall for the year
The average monthly rainfall
The month with the most rain
The month with the least rain

And the code:

double rain[] = new double [12];
double sum;
double average;
double most;
double least;

[code]....

I'm having a problem with figuring out how to show which month is the least and most.

View Replies View Related

Calculate Total Price And Display Total In Order Class

Oct 11, 2014

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?

View Replies View Related

Calculate Quantity / Price And Total Amount

Apr 10, 2015

How to calculate the qty and price and total of the amount in total column.

View Replies View Related

JSP :: Shopping Cart - Calculate Total Price

Sep 21, 2014

I am making a shopping cart web, but some problems I meet about how to calculate the total price

I use ajax in product list web and if I choose one product , it will send the Id that I read from MySql to servlet and use session to save it . and I click the button jump to the cart, the page cart.jsp will read information from session ,and find product information from mysql by id , now my question is where I calculate the total price, servlet or jsp?

View Replies View Related

For Loop - Calculate Total Of Series Of Numbers?

Nov 10, 2014

So basically, I've been trying to create a for loop that asks the user for a number between 1 and 30, then calculates the total of the series of numbers. For example, if 15 is entered, the calculation should be 1/15+2/14+3/13+...15/1 which would equal approximately 38.1. The problem I'm having is that the code doesn't loop whenever I type a number for some reason, which results in a very incorrect calculation. Here is my code so far:

import java.util.Scanner;
public class HmwLoop {
 public static void main(String[] args) {
double sum = 0;
for (double num1 = 1, num2 = 30; num1 <= 30 && num2 >= 1; num1++, num2--)

[Code] .....

View Replies View Related

Calculate And Display Normal / Overtime And Total Pay

Sep 12, 2014

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;

[Code] .....

View Replies View Related

Calculate All Total Amounts By Adding All Rows

Jun 12, 2014

table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
System.out.println("Value changed");
if(Float.parseFloat(table.getModel().getValueAt(table.getSelectedRow(), 4).toString()) != 0.0){
System.out.println(getTotal());
totalAmount.setText(""+getTotal());
}
}
});

This is what I've tried so far. What i want to do is to calculate all Total Amounts by adding all the rows (5th column only),as 5th column has total amount for 1 product, and set the text for a JTextField whenever the 5th column of any row changes its value.But this isn't working my way. I have also tried keyListener to trigger that change at Enter key typed but that also don't work for me.

View Replies View Related

Enter Customer Information And Calculate Total Bill

Feb 28, 2014

You have a store that sells the following items:

Shoes $50.00
T-shirts $30.00
Shorts $75.00
Caps $15.00
Jackets $100.00

Your sales associates need a program where they can enter customer information and calculate the customer's total bill. When the sales associate enters the program they should be presented with this main menu.

Enter customer information
Display Total Bill
Quit

If the sales associate selects option 1, the program should allow the sales associate to input their name, address, and e-mail address. Your program should then display this customer information to the screen with a message that the customer has been added to the customer list.

If the sales associate selects option 2, the program should ask the sales associate for the customer's name, product that the customer is purchasing, the quantity, and the price of the product. The total bill will then be displayed to the screen and should include the following:

- The customer's name.
- The product the customer is purchasing, the quantity, and total cost
- The amount of tax 8%
- The total cost with tax.

Example Total Bill Output:

John Doe

Product Purchased Quantity Total Cost
Shoes 2 $100.00
Tax 8%: $8.00
Total Cost: $108.00

HOW DO I WIITE IT

View Replies View Related

For Loop Program - Calculate Total Earnings For 30 Days

Oct 5, 2014

So I've attempted a for loop for this type of problem:If you receive $0.01 on the first day of your allowance, and the daily rate doubles each day after, calculate the total earnings for 30 days.

Output should be like:
Day ----- Daily allowance - Total allowance
1 -------- 0.01 -------------- 0.01
2 -------- 0.02 -------------- 0.03
3 -------- 0.04 -------------- 0.07

My code so far:

public class Allowance
{
public static void main (String[] args)
{
int day = 0;
double daily = 0.0;
double total = 0.1;
System.out.println("Day Daily Allowance Total Allowance");
for(day = 0; day <= 30; )

[code].....

View Replies View Related

Calculate Total Price At The End Of Order - Decimal Format

Apr 13, 2015

I have an assignment to create a JFrame pizzaorder and at the end of this order after the totalprice is calculated I need to format the number to ##.## but I keep getting a cannot find symbol error.

Source Code:

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
public class pizzaorder extends JFrame implements ItemListener, ListSelectionListener
//top section will have centered title telling the name, and under it seperate instructions to choose your pizza and toppings

[Code] ....

View Replies View Related

Calculate Total Amount Paid And Display It - NULL Error

Dec 10, 2014

Exception in thread "main" java.lang.NullPointerException
at ShoeStore.calculateTotal(ShoeStore.java:103)
at ShoeStore.main(ShoeStore.java:88)

This is the error when program is ran. The program is supposed to calculate the total amount paid for all shoes and display it.

import java.util.Scanner;
 public class ShoeStore
{
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String shoe_Name, nameStore, type;
int size, shoeAmount;
double sellingCost;
 
 [Code] .....

View Replies View Related

Baseball Team - Calculate Total Amount Of Home Runs Hit By Batters

Mar 24, 2014

So I have a class called Team that is a collection of players and managers for a baseball team, and one of my required methods is to calculate the total amount of Home Runs hit by the batters. Now along with the Team class I have an abstract Employee class, an abstract Player class and a Batter class that extends the Player class I thought this would be fairly easy but it is coming out to be pretty hard my code is as follow:

class Team {
public int _numPitcher;
public int _numBatter;
public String _manager;
public ArrayList<Player> team;
 
[Code] ....

The total salary works awesome but for some reason when I try and call up how many home runs a player has it wont call correctly I get this red line under my code that says: The method getHomeRuns() is undefined for type Player. I am trying to call this from the batter class which is an extension of the Player class...

View Replies View Related

Java GUI - Calculate And Display Total Cost For Certain Automotive Maintenance Services

May 12, 2014

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

[Code] .....

View Replies View Related

Calculate Total Sales After Each Football Game - JOptionPane (input / Output)

Mar 5, 2014

This specific assignment requires me to write a program that calculates the total sales after each football game. There are 4 types of tickets: box, sideline, premium, and general admission. After each game, data is stored in a file... then output the number of tickets sold and total sale amount. Format your output with 2 decimal places.

Okay I know there is a I/O section and wasnt sure where to post this. I need some insight on how to use file input and output as well ... Here is my program:

import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class ticketsSold
{
public static void main(String[] args)
{
String BoxSeat;
String SideLine;

[Code] ....

View Replies View Related

Calculate Fuel Economy Of Personal Car In Terms Of Gallons Per Mile And Total Cost For One Fill-up

Apr 4, 2015

public class CarV5
{
// private instance variables
String Model1;
int endMiles1, startMiles1;
double gallonsUsed1, pricePerGallon1;
 
[Code] .....

When I try to compile the program, its telling me that it cannot find the Dist variable in the main method for calcMPG and calcGPM. I'm not sure if the methods are right for the calcGPM or calcMPG.

View Replies View Related

Calculate And Store Value Into String The User Selected And Keeping It Going

Oct 28, 2014

This is the first time we are using 2 different classes. This is the code I have so far. What I am having trouble is doing the calculations and storing the value into the planet the user selected and keeping it going. I will attach the instructions ....

public class FakeGravity{
// Instance variables
private String planet;
private int VelocityDecay;
private double BouncinessFactor;
// default constructor
public FakeGravity(){

[Code] ....

View Replies View Related

Code That Add 1 To A Variable And Store It Anytime Key P Is Pressed On The Keyboard

May 7, 2015

a code that will add 1 to a variable and store it anytime key "p" is pressed on the keyboardKeep in mind

Here's what i have....

import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner kin = new Scanner (System.in);
int pa, ma;

[Code]...

View Replies View Related

Calculate Total Length Of N Number Of Bamboo Trees In M Number Of Seasons

Feb 20, 2014

In a forest, there are some bamboo trees .The length of each tree get doubled during winter and increases by one unit in summer , write a Java program to calculate the total length of n number of bamboo trees in M number of seasons. The season always starts with winter.

import java.util.Scanner;
public class Tree {
public static void main(String args[]) {
int length;
int season;

[Code] ....

View Replies View Related

Write A String Name Variable To Store Letters / Dotes And Spaces Only In Java?

Apr 5, 2014

I am trying to write a program and the name variable can only store letters,dotes and spaces. But whenever I enter a space, the program doesn't work. Following is my code.

import java.util.Scanner;
import java.util.*;
public class Space {
public static void main(String []args) {
Scanner reader = new Scanner(System.in);

[Code] ....

View Replies View Related

How To Get Total Number Of Pennies In Dollar Amount For The Output Of Total Pay

Mar 28, 2014

I cannot get the right output for my program. I need to get the total number of pennies in dollar amount for the output of Total Pay. This is my program. The directions are:

Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. Do not accept a number less than 1 for the number of days worked.

import java.util.Scanner;
import java.text.DecimalFormat;
public class PenniesForPay {
public static void main(String[] args) {
int numDays;

[Code] ....

totalSalary should be total number of pennies / 100....However its not picking up only day 30 of pennies which is 536,870,912 pennies and then dividing it?

View Replies View Related

Storing Months In Array And String Datatype

Oct 30, 2014

public class MonthsName
{
static String monthsName[];
public static void main(String[] args) {
String[] months = new String[13];
months[0] = null ;

[Code] .....

I keep getting 1 error that tells me this.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at MonthsName.main(MonthsName.java:22)
Java Result: 1

Just before that netbeans couldn't find the main class. I was wondering if it netbeans or my code that's wrong.

View Replies View Related

Iterating Through Months While Keeping In Mind Different Length Of Month

May 20, 2015

I have to create a method to find the current month with the input being a number of milliseconds using System.currentTimeMillis(). Now I was able to solve the problem with the following extremely cumbersome method:

public static int monthLeap(long ms) {
int result = 0;
int jan = 31, mar = 31, may = 31, jul = 31, aug = 31, oct = 31, dec = 31;
int apr = 30, jun = 30, sep = 30, nov = 30;
int feb = 28;
int febLeap = 29;

[Code] ....

I first go through a loop that goes through all the years and subtracting the number of days of a normal year or a leap year in milliseconds from the total milliseconds. At the end I should have a rest value of milliseconds that represents the amount of milliseconds that have passed already this year. Out of this number I then find the month we are currently in.

My problem is that the above method is way to large and I get a checkstyle warning: "NPath Complexity is 12,288 (max allowed is 80)".

I know that this can somehow be solved with a for loop iterating through the time and counting up months until there is no more month left. My problem though is the different lengths of the months. If each month was the same I could just subtract the amount of days in each month from the rest value.

(Since I already got it down to <= 12 months, I shouldnt bother with the extra days to find the month. Yet if I want to find the month when the date is the first or last day of the month it is important to be very precise) ....

View Replies View Related

Program That Calculates How Much Employees Earn Over A Period Of Time In Months

Oct 5, 2014

i am very new to java programming what i am doing wrong here. Write a program that calculates how much an employee would earn over a period of time (in months), if, every month, the employee’ pay-per-hour rate is one dollar more than the month before (so if his starting perhour rate is 7.25, next month it will be 8.25, next month 9.25, and so on). The employee is going to work 20 hours per week, 4 weeks per month.

The program should input from the user and validate both number of months (which should be a positive integer larger than 0) and the pay-per-hour rate (which should be a floating-point number larger than $7.25 – the minimum federal wage pay-per-hour rate). For each one of these values; if the value is wrong, the program should repetitively ask for that value until the value entered is correct. The program should confirm/output the correct value.

/*
This program calculates how much as employee would earn if every month the employee pay per hour would increase by a dollar
*/
package nick.employee;
import java.util.Scanner;
public class nickemployee {

[Code]...

what i am doing wrong

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved