Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners illegal start type, HELP!
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Colin White
illegal start type, HELP!
2 Answer(s)      3 years ago
Posted in : Java Beginners


import java.util.Scanner;

public class Lab6ex9 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in);

    System.out.print("Please type the total number of books: ");
    int books = keyboard.nextInt();

    System.out.print("Please type the total value of the purchase: ");
    double total = keyboard.nextDouble();

    if (total >= 50)
    {
        System.out.println("Total number of books: " + books);
        System.out.println("Total value of books: " + total);
        System.out.println("Shipping is free!");
    }
    else if(total < 50 && books =< 3)
    {
        double shipping = total *0.1;

        System.out.println("Total number of books: " + books);
        System.out.println("Total value of books: " + total);
        System.out.println("Shipping cost is " + shipping + " dollars.");
    }
    else if(total < 50 && books >= 3 && books < 10)
    {
        double shipping = total *0.2;

        System.out.println("Total number of books: " + books);
        System.out.println("Total value of books: " + total);
        System.out.println("Shipping cost is " + shipping + " dollars.");
    }
    else if(total < 50 && books >= 10)
    {
        double shipping = total *0.3

        System.out.println("Total number of books: " + books);
        System.out.println("Total value of books: " + total);
        System.out.println("Shipping cost is " + shipping + " dollars.");
    }
}

}

Illegal start type error? help?


Advertisement
View Answers

October 18, 2011 at 10:30 AM


import java.util.Scanner;

public class Lab6ex9 {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);

    System.out.print("Please type the total number of books: ");
    int books = keyboard.nextInt();

    System.out.print("Please type the total value of the purchase: ");
    double total = keyboard.nextDouble();

    if (total >= 50)
    {
        System.out.println("Total number of books: " + books);
        System.out.println("Total value of books: " + total);
        System.out.println("Shipping is free!");
    }
    else if(total < 50 && books <= 3)
    {
        double shipping = total *0.1;

        System.out.println("Total number of books: " + books);
        System.out.println("Total value of books: " + total);
        System.out.println("Shipping cost is " + shipping + " dollars.");
    }
    else if(total < 50 && books >= 3 && books < 10)
    {
        double shipping = total *0.2;

        System.out.println("Total number of books: " + books);
        System.out.println("Total value of books: " + total);
        System.out.println("Shipping cost is " + shipping + " dollars.");
    }
    else if(total < 50 && books >= 10)
    {
        double shipping = total *0.3;

        System.out.println("Total number of books: " + books);
        System.out.println("Total value of books: " + total);
        System.out.println("Shipping cost is " + shipping + " dollars.");
    }
}

}


October 18, 2011 at 10:41 AM


Hi Now the is running here......

I think you have made mistake here

double shipping = total *0.3 please insert semicolon after the expression

import java.util.Scanner;

public class ScannerExample {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Please type the total number of books: ");
        int books = keyboard.nextInt();

        System.out.print("Please type the total value of the purchase: ");
        double total = keyboard.nextDouble();

        if (total >= 50) {
            System.out.println("Total number of books: " + books);
            System.out.println("Total value of books: " + total);
            System.out.println("Shipping is free!");
        } else if (total < 50 && books <= 3) {
            double shipping = total * 0.1;

            System.out.println("Total number of books: " + books);
            System.out.println("Total value of books: " + total);
            System.out.println("Shipping cost is " + shipping + " dollars.");
        } else if (total < 50 && books >= 3 && books < 10) {
            double shipping = total * 0.2;

            System.out.println("Total number of books: " + books);
            System.out.println("Total value of books: " + total);
            System.out.println("Shipping cost is " + shipping + " dollars.");
        } else if (total < 50 && books >= 10) {
            double shipping = total * 0.3;

            System.out.println("Total number of books: " + books);
            System.out.println("Total value of books: " + total);
            System.out.println("Shipping cost is " + shipping + " dollars.");
        }
    }
}


Related Tutorials/Questions & Answers:
 

 

 

DMCA.com