5 Replies - 724 Views - Last Post: 24 September 2012 - 03:48 PM Rate Topic: -----

#1 DCole  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-September 12

Shipping Charges java code. Still needs zip code specifications

Posted 23 September 2012 - 03:09 PM

import java.util.Scanner;           // Required for the Scanner class.

public class ShippingCharges2

{

    public static void main (String[] args)

		{
int zipcode;	//Enter zipcode
int weight;		//Enter weight of package
int length;		//Enter length of package
int width;		//Enter width of package 
int height;		//Enter height of package


Scanner input = new Scanner(System.in);         // Create a Scanner object for the input.

//Get the zipcode of the package
System.out.println(" What is the zipcode for th package? ");
zipcode = input.nextInt();

//Get the weight of the package
System.out.println("What is the weight of the package (in pounds)? ");
weight = input.nextInt();

//Get the length of the package
System.out.println("What is the length of the package (in inches)? ");
length = input.nextInt();

//Get the width of the package
System.out.println("What is the width of the package (in inches)? ");
width = input.nextInt();

//Get the height of the package
System.out.println("What is the height of the package (in inches)? ");
height = input.nextInt();

if("Shipping charges=0 ");
	{
	if(weight <= 5)
		System.out.println("Shipping cost is: $12.00 ");
		}
	else if(weight > 5 && weight <= 15);
	{
		System.out.println("Total Shipping Cost is: $14.00 ");
		}
	else if(weight > 15 && weight <= 34);
	{
		System.out.println("Total Shipping cost is: $17.00 ");
		}
	else if(weight > 34 && weight <= 45);
	{
		System.out.println("Total Shipping cost is: 21.00 ");
		}
	else if(weight > 34 && weight <= 45);
	{
		System.out.println("Total Shipping cost is: 33.00 ");
		}
	else
	{
		System.out.println("Total Shipping cost is 105.00 ");
		}



This is what I have so far and I keep getting the error 'else' without 'if'
Can you let me know if there is anything else wrong with it so far and how to fix my probelm, Ive been trying to fix it for a while now.

*Edited: please :code:

This post has been edited by pbl: 23 September 2012 - 03:15 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Shipping Charges java code. Still needs zip code specifications

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2556
  • View blog
  • Posts: 10,664
  • Joined: 20-September 08

Re: Shipping Charges java code. Still needs zip code specifications

Posted 23 September 2012 - 03:12 PM

Quote

if("Shipping charges=0 ");


Get rid of all the semicolons
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7294
  • View blog
  • Posts: 12,138
  • Joined: 19-March 11

Re: Shipping Charges java code. Still needs zip code specifications

Posted 23 September 2012 - 03:16 PM

View Postg00se, on 23 September 2012 - 05:12 PM, said:

Quote

if("Shipping charges=0 ");


Get rid of all the semicolons


Or at least, the ones separating an if condition from its associated statement block.
int height; 


This one is okay. :)
Was This Post Helpful? 0
  • +
  • -

#4 DCole  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-September 12

Re: Shipping Charges java code. Still needs zip code specifications

Posted 23 September 2012 - 03:34 PM

This is what I have so far but I do not know how to add:

The additional charges are calculated as follows:
If the first digit of the zip code is a "4" then there is an additional surcharge of 5% on
the shipping cost.
If the first digit of the zip code is a "6" then there is an additional surcharge of 9% on
the shipping cost.
For all other zip codes there is an additional surcharge of 14% on the shipping cost.


Finally, if the zip code is even, then there is an additional surcharge of 2% of the
shipping cost.
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2556
  • View blog
  • Posts: 10,664
  • Joined: 20-September 08

Re: Shipping Charges java code. Still needs zip code specifications

Posted 24 September 2012 - 03:28 AM

Post your fixed and running code first
Was This Post Helpful? 0
  • +
  • -

#6 DoinWork  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 69
  • Joined: 26-October 11

Re: Shipping Charges java code. Still needs zip code specifications

Posted 24 September 2012 - 03:48 PM

As they stated, having a if statement followed by a semicolon(;) essentially is a no-op meaning it basically checks the if, but then just keeps reading like it doesn't matter.

For the additional charges, in your if-else statements above I wouldn't print out the shipping charge. Instead keep a variable of it for that part. Also, I think you have one too many brackets just below that "Shipping cost is 12.00" line.
if(shippingCharges==0.0){
  if(weight <= 5)
    shippingCharges=12.00;



Then afterwords call a method to pluck off the first number of the int, then adjust the pricing variable accordingly. Then print it at the end.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1