logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    sfolax6776
    Jun 27, 2019
      ·  Edited: Dec 23, 2020

    1.5 What makes a Java program and what is a class ?

    in Introduction to Java

    A. Introduction

    Programs don't come out of nowhere. They exist to solve problems or provide some functionality. More or less, a program always has three parts: input, processing and output. This applies to a small program such as calculating phone charges, as well as a large application such as an online store. The processing algorithms are designed to take the input and generate the desired output.

    Notice your program always start from a "project", then you will have to create a "class". What is a class anyway?

    B. Watch... (Slides)

    C. Try:

    1. PhoneCharge.java is here. Change it to read minutes from keyboard and print out the total charge with two decimal places and a leading $. For instance, $102.75

    2. Bonus:

    The following pseudocode describes how a bookstore computes the price of an order from the book price and the number of the books that were ordered.
    
    Read the book price and numbers of books from a data file.
    Compute the tax (7.5 percent of the total book price).
    Compute the shipping charge ($2 per book).
    The price of the order is the sum of the total book price, the tax, and the shipping charge. Print the price of the order, with two decimal places and a leading $.
    
    Translate this pseudocode into a Java program.

    2 comments
    0
    madisondee5
    Jan 19, 2020

    import java.util.Scanner;

    class bookstore {

    public static void main(String[] args) {

    Scanner inputfromscanner = new Scanner(System.in);

    double bookprice=0.0, taxpercentage, shippingcharge, totalbeforetax,

    totalwithtax, totalwithshipping;

    int numbooks;


    taxpercentage = 7.5;

    shippingcharge = 2.0;


    System.out.print("Please enter the number of books:3");

    numbooks = inputfromscanner.nextInt();



    for(int x=0;x<=numbooks;){

    if( x = numbooks ) {

    break;

    }


    System.out.print("Please enter the before-tax price of the book");

    bookprice = inputfromscanner.nextDouble();


    }

    inputfromscanner .close();

    totalbeforetax = bookprice;

    totalwithtax = totalbeforeTax*Taxpercentage;

    totalwithshipping = totalwithtax + (numbooks*shippingcharge);



    System.out.print("The total price of the order is");

    System.out.println(totalwithshipping);

    }

    }


    0
    madisondee5
    Jan 19, 2020

    Im not sure if it is correct

    0
    2 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners