AllFreePapers.com - All Free Papers and Essays for All Students
Search

Introduction to Computer Science

Autor:   •  November 27, 2017  •  Exam  •  2,420 Words (10 Pages)  •  692 Views

Page 1 of 10

(Question 1)

import java.util.Scanner;

public class testingquestion1 {

      public static void main(String[] args)

    {

        Scanner temp = new Scanner (System.in);

        int employeenumber;

        double retailprice, commission;

        char code;

        System.out.println("Enter employeenumber:");

        employeenumber = temp.nextInt();

        System.out.println("Enter the retailprice of an item:");

                retailprice = temp.nextDouble();

                System.out.println("Enter the price of code:");

                code = temp.next().charAt(0);

                if (code=='A' || code=='a')

                {

                    commission = retailprice * 0.06;

                    System.out.printf("the commission is:$%.2f\n",commission);

                }

                else if (code=='B' || code=='b')

                {

                    commission = retailprice * 0.08;

                    System.out.printf("commission is:$%.2f\n",commission);

                }

                else if (code =='C' || code =='c')

                {

                    commission = retailprice * 0.10;

                      System.out.printf("commission is:$%.2f\n",commission);

                }

                else

                {

                    System.out.println("Invalid code");

                }

    }

}

Screenshot(output) for question 1

[pic 1]

Explanation: For question one it is hard to figure out how to code properly because it is hard to figure how the flower bracket works on Java script compared to MATLAB. Firstly i made an mistake on running too many time to make the program execute, so i manage to figure out i have to close all the running test to RUN the question 1 output. secondly mistake i made is about the flower bracket. once a RED colour underline i can't execute the program i have to figure out when to open or close the flower brackets, Example: IF Open flower bracket hit "Enter" for display  commission = retailprice * 0.06; and  display commission (System.out.printf("the commission is:$%.2f\n",commission);) and a close bracket is auto typed by java programming. as for question compared to the other 2 question there is a challenging part where i have to figure how to put the Input, double and char code.

...

Download as:   txt (9.4 Kb)   pdf (524.9 Kb)   docx (402.6 Kb)  
Continue for 9 more pages »