WHAT'S NEW?
Loading...

Programming Pre final examination CS and IT


Develop a Tour price transaction system in different country in ASIA. The customer can view and select where the country they want to travel.  For instance, the customer can only select one country at a time to process his/her transaction and pressing only one character or number they want to select. Adults and children have different rate it depends the country they want to travel.  Supposed the customers decide on what country they want to tour, the system will also have a list of country available and price of adults and children assigned in a given country. Let’s look the figure given.
Country Name:
Adult Price
Children Price
Singapore
$500
$300
Malaysia
$700
$500
Thailand
$500
$500
Japan
$800
$600
Hongkong
$400
$300
Vietnam
$500
$400
Brunei
$600
$500
China
$700
$600
Indonesia
$300
$300
Taiwan
$500
$500

Now, we have a given price of every country at the same time the price of adult and children.

In order to perform the customer transaction, the customers first select the country name so that the customers should be able now to input the number of adults and children given the price of every country. However, there’s supposed to have a 12% tax interest of every customer’s travel in a total rate. Now, compute a total rate of customer’s and get the 12% tax interest of a total price.

Used either if, case, and do loop statement or both as long it handle the process of a program.

Sample output:

Name of Country:            Singapore
Number of Adults:           2
Number of Children:        3
Total Price of Adults:      1000
Total Price of Children    900
Total Rate:                      2128
Tax Rate Interest (12%)  228

Write your flowchart output in a one whole band paper.

Do loop statement exercises



·         Create a program that computes customers items purchased using do loop statement. For example, the customer buys 3 apples and 2 oranges and a customer ask again to double check if the item purchased computed accurately. The program will continue processing until the transaction meets the maximum items order, it depends how you are going to handle the transaction. The user can terminate the program either pressing Yes (Y) to continue to compute again or No (N) to exit the transaction.
o   Note: You need first the input from the user to process the output.
o   Write your algorithm and flowchart answer on a one whole yellow pad paper.
·         Write a program that the user can input a starting number and end number, it’s up for the user where it begins and will it end. Used do loop statement. Example the user input a number 2 for starting number and 10 for end number. The output would be 3, 4, 5 … 10.
o   Note: You need first the input from the user to process the output.
o   Write your algorithm and flowchart answer on a one whole yellow pad paper.
·         Create a program that will print a number from highest to lowest, example the user input the end number 8 and 2 is the index number. The output would be 7, 6, 5 … 1. Used do loop statement.
o   Note: You need first the input from the user to process the output.
o   Write your algorithm and flowchart answer on a one whole yellow pad paper.
·         Write a program the will print a number increment by 5. Used a constant index or starting number at 0. Let the user input a number and should not less than 20 to enable the output visible by 5. Example output would be 5, 10 … 20.
o   Note: You need first the input from the user to process the output.
o   Write your algorithm and flowchart answer on a one whole yellow pad paper.

Comparing String method in Java


In Java programming language, comparing string method also used compareTo keyword to compared character by character using the Unicode collating sequence. This kind of methods reads the number of character and compared it to the next character, if the character matched to the compared character, next character will be read again to match, if there’s no character will the same to the next, next character will be read  and compared it. For instance, supposed string “cat”, cat is less than “dog” character, because in alphabetical order c is first character to read than to d. Another example, supposed String “met and “meat”. When you noticed the first two characters are both the same in “me” at met and “me” at meat, so, the next third character will be read and “a” is less that “t”. The evaluated out first will be “met”. How about the similar length of character and same word, like for example string “Java” and “java”. To read, string “Java” is less than the string “java” because the first character “J” of “Java” is less than the first character “j” of “java”. To make it clear, I will give a sample code in java using comparing string method in java.

Sample code 1:

String h1 = "met";
String h1 ="meat";
             
System.out.println(h1.compareTo(h2));
 if (h1.compareTo(h2)<0)
  {
   System.out.println("It is true");
  }else
   {
    System.out.println("It is false");
   }

Output:
19
It is false

Why it is become 19? When you observed, string h1 and h2 value both the same for the two characters ‘m’ and ‘e’. So, the next character ‘a’ and ‘t’ next to be compare. Now, count the alphabet from “a” to “t” start counting from “b”. The if condition will determine if it is return true or false. So, the result is false because string “met” is less than “meat”. If you are going to reverse h1 string to “meat” and h2 to “met” the equivalent output is -19 and it returns to true because -19<0.

Sample code 2:

String h1 = "java";
String h2 = "Java";
             
System.out.println(h1.compareTo(h2));
 if (h1.compareTo(h2)<0)
  {
   System.out.println("It is true");
  }else
   {
    System.out.println("It is false");
   }

Output:
32
It is false

In addition, methods equals in java, also similar in comparing a string. However, it returns the value true or false. The good thing is we can compare two strings to determine if it is equal to the given value. For example, guessing game, if the user didn’t guess what is given, will display and error message otherwise you’ve got it. Here is the sample code.

String name;
String guess = "Java";
                  
System.out.print("Guess me: ");
name = input.nextLine();
             
System.out.print("Confirm: ");
guess = input.nextLine();
             
 if (name.equals(guess)==true)
  {
   System.out.println("You've got it!");
  }
  else
   {
    System.out.println("Error");
   }

Unfortunately, we can also use char data types to determine if the input of a user is less than or greater than. Here is the sample written code below. We determine using if statement where among the two is less than based on the character inputted by the user.

char ch1;
char ch2;
      
System.out.print("Enter first character: ");
ch1 = input.next().charAt(0);
System.out.print("Enter second character: ");
ch2 = input.next().charAt(0);
             
if (ch1<ch2)
 {
  System.out.println("The first character you entered is less that the second one");
 }else
  {
   System.out.println("The second character you entered is greater that the first one");
  }