Posts

Showing posts from October, 2022

Exercise 2 Predefined Class

Image
Question 1:   public class PredefinedClass {     public static void main(String[] args) {         String a = "Number", b = "Square", c = "Cube";         System.out.printf("%s%8s%7s", a,b,c);         int n = 0;         do{             double sq = Math.pow(n,2);             double cb = Math.pow(n,3);             System.out.printf("%n%d%10.0f%9.0f",n,sq,cb);             n++;     }while(n<=10);         System.out.println("");     } }     Question 2: import java.util.Scanner; public class CountA {     public static void main(String[] args) {         Scanner sc = new Scanner (System.in);         System.out.print("Input a word: ");         String x ...

Exercise 1 Revision String

Image
 1.  public class StringExercise {     public static void main (String[] args) {           String college = new String ("College of Arts and Sciences");  String town = new String (" UUM Sintok") ; // part (a)  int stringLength;  String change1, change2, change3;  stringLength=college.length(); // part (b)  System.out.println (college + " contains " + stringLength + " characters.");  change1 = college.toUpperCase(); // part (c)  System.out.println ("The string is all in upper case: " + change1);  change2 = change1.replaceAll("O","*"); // part (d) System.out.println ("All capital O's are replaced with the asterisk character: " + change2);  change3 = college.concat (town) ; // part (e)  System.out.println ("The final string is " + change3);       }  } 2.  import java.util.Scanner; public class FunnyStringExc{     public static void main(String[] args) ...

Exercise UML

Image
  School of Computing, UUM College of Arts and Sciences STIA1123 PROGRAMMING 2 Exercise : Introduction to OOP Concept 1.         Given the following incomplete code: Draw a UML class diagram representing the code. House -houseType : String -houseAddress : String -housenoOfRooms : int -housePrice : double + setPrice(double): void  + getAddress() :String + calculateMonthlyPayment(int): double 2.          Based on the following scenario, answer the following questions:   You are appointed to develop a program for Philipsi Pressure Cooker company. The program should keep information about the pressure cooker which includes String for model (e.g. HD2139, RL1198, BF2222, EPC-6000s), char for size (e.g. L (large), M (medium), S (small)), String for colour (brown, silver, golden, white) and double for price (e.g. RM309.00, RM169.00, R...

Exercise OOP Concept

Image
School of Computing, UUM College of Arts and Sciences STIA1123 PROGRAMMING 2 Lab Exercise : Introduction to OOP Concept    1.    Given the following UML Class diagram: Bike -bikeColor : String -bikePrice : double +getBikeColor(String): String +calculateMonthlyPayment(): double +getBikePrice(String): double +printBikeInfo(): void                        a)    Identify   o    Class name: bike o    Object: bicycles &motorcycles o    Attributes and its data types : color: String , Price: double o    Methods: getBikeColor (String), calculateMonthlyPayment(), getBikePrice(String), printBikeInfo() b)    Determine the types of method and the data types of values returned.   1.      GetBikeColor() is a value returning method and will return a Str...