Get Input From User To Be Multiplied By Package Cost - Discounted Total?
May 12, 2014
I am new to java and this is one of my first program assignments. I can't figure out how to make the if else statements work. I am trying to get the input from the user to be multiplied by the package cost but it gives me an error. I also can't figure out how to solve for the discounted total.
Purpose of the program: To write a program that asks the user to enter the number of packages purchased. The program should then display the amount without any discount, the amount of the calculated discount (if any), and the total amount of the purchase after the discount is applied.
What the output should be:
Enter the number of packages purchased: 10
Your total without discount: $990.00
The discount is: $198.00
The discounted total: $792.00
import java.util.Scanner;
public class Practice {
public static void main(String[] args) {
double packageCost = 99.00;
double amtPackage = 10.00;
double withoutDiscount = packageCost * (double) amtPackage;
A wages calculator application is required that can determine the total cost of crew departing from the port on that day. To do this, the application reads from an itinerary text file containing each ship being loaded in the port that day, in the following format:
<ship id> <journey id> <l> // where <l> is the length in hours of the journey <s> // where <s> is the number of crew for the ship for this journey <rate> // for each s, <rate> is hourly rate of pay
Your application must calculate the total cost of the crew for each ship/journey and then compare it with a "recommended maximum journey cost" (RM) amount typed in by the user when the application is first run. If the total amount is less than or equal to RM then the details must be written to the screen and to an output text file called wagedaily.txt. If the amount is larger than RM then the results must be written to the screen only. Messages to the screen must indicate whether the crew cost is less than, equal to or larger than RM.
Your application should find the ship with the highest crew cost that is below RM and print this out as the final piece of output to the screen.
It has given me a bunch of ships and numbers to play around with in the code, here they are:
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
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.
import java.util.Scanner; public class BellmanFord { private int distances[]; private int numberofvertices; public static final int MAX_VALUE = 999;
[Code] ....
I am trying to display two types of table one with initial cost and another one with new cost. Based on the java code here i already have one table but don't know how to display another table.
Attached is the sample output that i am aiming for. The output table for the above code is:
distance of source 1 to 1 is 0 distance of source 1 to 2 is 4 distance of source 1 to 3 is 3 distance of source 1 to 4 is -6 distance of source 1 to 5 is -1 distance of source 1 to 6 is 2
I think I fixed the first error, but now I'm receiving another error in my Net Pay print statement at the end.
Here is what I'm supposed to receive:
Net Pay: 599.86
Here is my sample run:
run-single: Enter hourly rate in dollars and cents --> 27.16 Enter number of hours and tenths worked --> 37.9
PAYROLL REPORT Rate: 27.16 Hours: 37.9
Gross Pay: 1029.36 Federal Tax: 257.34 State Tax: 93.41 FICA: 78.75 Net Pay: 771.86
Employer's FICA contribution: 78.75 Employer's UEI and DI contribution: 20.59 Cost to Employer: 1128.70
Enter hourly rate in dollars and cents -->
Here is my updated code:
package assignmentproject1; /* CHANGE (FINAL) VAR NAMES, SCAN & VERIFY, ORGANIZE AND PUT FORMULAS ON BOTTOM, ORGANIZE VAR @ TOP, */ import java.util.*; public class Project1 { public static void main (String[] args)
My working directory is e:ajava. in package p1 i create two classes c1 and c2. net beans creates three files e:ajavap1srcp1, e:ajavap1srcc1, e:ajavap1srcc2. package runs without a hitch. i create another package p2 under e:ajava. i want to use class c1 in p2. pray what on earth should be my import statement in the p2 source code after the first statement 'package p2'. another related querry what should i include in my class path so as to gain access to c1 and c2 in source code of p2.
I wanted to write a simple code that receives information from the user (double-digit number and above) and calculates it's numbers.
For instance- The user wrote a number- 234, the software will return the number 9 (2+3+4 = 9).
Tried to use a loop for that, but I got stuck since I didn't know what to write.
This is what I've wrote so far
Java Code:
import java.util.Scanner; public class Calculate { public static void main(String[] args) { System.out.println("Please type a number larger than 9"); Scanner type = new Scanner(System.in); String number1 = type.nextLine();
for( int i = 0; i < number1.length(); i++ ){ int calculate = number1.charAt(i); } } } mh_sh_highlight_all('java');
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;
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber { Scanner scan = new Scanner(System.in); int userNum; String neg;
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?
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?
class Client{ public static void main(String []args){ Bike R1=new Bike(5.0, 60.0,30.0);//create bike object with params Bike R2=new Bike();//without params System.out.println(R1.increaseSpeed());//calling methods System.out.println(R1.maxDistance()); System.out.println(R2.increaseSpeed()); System.out.println(R2.maxDistance()); } }
Let's say hypothetically you're making a huge program and use a lot of imports (ex import java.util). If you only need a few specific things from java.util, will it use more memory importing java.util.* compared to only importing lets say java.util.Scanner, java.util.ArrayList, etc. Basically does importing a whole package use more (if any at all) memory than only importing specific package parts?
I have been coding in my class at school (Grade 11 Computer science) and i just downloaded the program on my computer at home, unfortunately i cannot access my computer notes at home and i also dont remember certian specifics of coding, so my question is how would i get user input to create a program. The comments are the parts i dont remember. (I am trying to slowly build my memory with this stuff)
Here is my code so far:
import java.util; [highlight=java] public class hello_world { public static void main(String[] args) { string name; //WHAT DO I PUT HERE????
I'm working on creating a dice game and getting the users input is giving me a really hard time. I have the main game working but this part I'm stuck on. The problem is that it's not giving me the chance to enter the second input when I ask for the game.
//Create Scanner object Scanner keys = new Scanner(System.in); //Get chips
[Code]....
*****This is what I get when I run it
run:
How much money would you like to change? 50
You now have $50 in chips.
What game do you want to play? You did not pick dice.
I have been given a piece of work to do for College that requires me to format user input. For example: This is an example of text that will have straight left and right margins after formatting
The user inputs the width, in the case above being 20. Each line has to therefore be 20 characters long. All spaces are to be replaced with full stops.
This.is.an.example.o f.text.that.will.hav e.straight.left.and. right.margins.after. formatting.......... public class Main { public static void main ( String args[])
ArrayList<Integer> leftCU = new ArrayList<>(); { System.out.println ("Please enter one at a time the number of CU's for each class that is left to complete. Enter Q when done."); leftCU.add(in.nextInt());
I'm working on creating a dice game and getting the users input is giving me a really hard time. I have the main game working but this part I'm stuck on. The problem is that it's not giving me the chance to enter the second input when I ask for the game.
//Create Scanner object Scanner keys = new Scanner(System.in); //Get chips System.out.print("How much money would you like to change? "); int chips = keys.nextInt(); System.out.println("You now have $" + chips + " in chips.");
[code]...
This is what I get when I run it run/How much money would you like to change?
I created a scanner object but it's not asking for any input. when I create a new scanner and then tell it to print it it just prints a bunch of weirdness when AFIK it should be asking me to type something and then it should repeat what i entered.