Graderpractice for programmers

254275 OOP Lab 5-10 2/2563

Awaiting submission
A Starbucks Shop has a menu and a size Complete the StarbucksShop class by writing 2 methods:
* getSize returns the size as a String (short, tall,grande,venti)
* getMenu returns the menu of StarbucksShop

Test code:

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        StarbucksShop d = input();

        System.out.println("Drink name: " + d.getMenu());
        System.out.print("Size: ");
        switch (d.getSize())
        {
            case "short":
                System.out.println("Short"); break;
            case "tall":
                System.out.println("Tall"); break;
            case "grande":
                System.out.println("Grande"); break;
            case "venti":
                System.out.println("Venti"); break;
        }
   }
      private static   StarbucksShop input() 
      {
          String name = sc.nextLine();
          String container = sc.nextLine();
          return new   StarbucksShop(name, container);
      }
  
Awaiting submission
Reuse your Starbuck class from question 1. Add a method named toString that returns the menu the size and the name Customer
private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args)
    {
        StarbucksShop d = input();
        System.out.println(d.toString());
    }

    private static StarbucksShop input()
    {
        String menu = sc.nextLine();
        String size= sc.nextLine().toLowerCase();
        String name = sc.nextLine();
        return new StarbucksShop(menu,size,name);
    }
Awaiting submission
Reuse your Starbucks class from question 2. Add a method named getContainerDescription that returns "Normal glass", "Starbucks glass" as a String for the container name.
  private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        StarbucksShop d = input();

        System.out.println(d.getContainerDescription());
    }

    private static StarbucksShop input()
    {
        String menu = sc.nextLine();
        String size = sc.nextLine();
        char container = sc.nextLine().charAt(0);
        return new StarbucksShop(menu, size, container);
    }
Awaiting submission
Reuse your Starsbuck class from question 3. Add a method named isSameName that takes another Drink and returns true if they have the same name.
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
         StarbucksShop d1 = input();
         StarbucksShop d2 = input();

         if (d1.isSameName(d2)) {
             System.out.println("Drink 1 and Drink 2 is the same menu");
         }
         else {
             System.out.println("Not the same menu");
         }
     }

     private static StarbucksShop input() {
         String menu = sc.nextLine();
         String size = sc.nextLine();
         char container = sc.nextLine().charAt(0);
         return new StarbucksShop(menu, size, container);
     }
Awaiting submission
Palace of Atom, also known as "Wang Dong Programmer", this elegant place is full of knowledge of Various programming The palace is located at Phitsanulok - Nakhon Sawan 99 Moo 9, Tha Pho Subdistrict Tha Pho, Mueang Phitsanulok District, 65000 The key is that this palace has been stung by programmers as Provide the best programming knowledge
Write a class named Palace with fields for "castle" and "principality".
  • getCastle returns the number of castles
  • getPrincipality returns the number of principality
Template:
 public static void main(String[] args)
 {
      Scanner sc = new Scanner(System.in);
      Palace p = new Palace(sc.nextInt(), sc.nextInt());
      System.out.print("Palace of Atom has "+p.getCastle()+ " Castle");
      if(p.getCastle()>1)
      {
          System.out.print("s");
      }
      System.out.print(" including "+p.getPrincipality()+" Principality");
      if(p.getPrincipality()>1)
      {
          System.out.print("s");
      }
   }
Awaiting submission
Add a new method to the Palace named toString that returns amount of the castle and principality
Template:
  public static void main(String[] args)
  {
      Scanner sc = new Scanner(System.in);
       int castle = Integer.parseInt(sc.nextLine());
       int principality = Integer.parseInt(sc.nextLine());
       Palace p = new Palace(castle,principality);
       System.out.println(p.toString());
  }
.
Awaiting submission
A Large Palace is a with if the castle more than 5 and principality 8 . Add a method named is LargePalace that returns true if the Palace is Large Palace
  public static void main(String[] args)
  {
        Scanner sc = new Scanner(System.in);
        int castle = Integer.parseInt(sc.nextLine());
        int principality = Integer.parseInt(sc.nextLine());
        String name = sc.nextLine();
        Palace p = new Palace(castle,principality,name);
        if (p.LargePalace()==true)
        {
          System.out.println(p.getName()+" is a Large Palace");
        }
        else
        {
          System.out.println(p.getName()+" is a Normal Palace");
        }
  }
Awaiting submission
Castles have owner. Add a method named is IsyouCastle that returns true if the correct name Castle owner
  • Vachirapon Tosawat owns the java
  • Piyachok Seangbuddee owns the the python
  • Nanthaphong Khongyut owns the the kotlin
  • Thadaphong Kesornprom owns the the swift
  • Puwanasul Klanhun owns the ruby
  • Panuphun Injan owns the javascpit
public static void main(String[] args)
{
      Scanner sc = new Scanner(System.in);
        int castle = Integer.parseInt(sc.nextLine());
        int principality = Integer.parseInt(sc.nextLine());
        String owner = sc.nextLine().toLowerCase();
        String name = sc.nextLine().toLowerCase();
        Palace p = new Palace(castle,principality,name,owner);
        if (p.isyourCastle()==true)
        {
          System.out.println(p.getOwner()+" is the owner of the "+p.getName()+" castle.");
        }
        else
        {
          System.out.println(p.getOwner()+" isn't the owner of the "+p.getName()+" castle.");
        }
 }
Awaiting submission
Complex numbers are those that have an imaginary part and a real part associated with it. They can be added and subtracted like regular numbers. The real parts and imaginary parts are respectively added or subtracted or even multiplied and divided.
The value of a complex numbers is calculated by The real parts + reals parts and imaginary part+ parts Complete the class Complex by adding a constructor and methods for getting real,img and sum
 public static void main(String args[])
 {
     Scanner sc = new Scanner(System.in);
     ComplexNumber c1 = new ComplexNumber(sc.nextDouble(),sc.nextDouble());
     ComplexNumber c2 = new ComplexNumber(sc.nextDouble(),sc.nextDouble());
     ComplexNumber ss = sum(c1, c2);
     System.out.printf("The sum of two complex numbers is "+String.format("%.1f",ss.real)+" + "+String.format("%.1f",ss.img) +"i");
 }
Awaiting submission
In mathematics, a parabola is a plane curve which is mirror-symmetrical and is approximately U-shaped. It fits several superficially different mathematical descriptions, which can all be proved to define exactly the same curves.
One description of a parabola involves a point (the focus) and a line (the directrix). The focus does not lie on the directrix. The parabola is the locus of points in that plane that are equidistant from both the directrix and the focus. Another description of a parabola is as a conic section, created from the intersection of a right circular conical surface and a plane parallel to another plane that is tangential to the conical surface.[a]
The line perpendicular to the directrix and passing through the focus (that is, the line that splits the parabola through the middle) is called the "axis of symmetry". The point where the parabola intersects its axis of symmetry is called the "vertex" and is the point where the parabola is most sharply curved. The distance between the vertex and the focus, measured along the axis of symmetry, is the "focal length". The "latus rectum" is the chord of the parabola that is parallel to the directrix and passes through the focus. Parabolas can open up, down, left, right, or in some other arbitrary direction. Any parabola can be repositioned and rescaled to fit exactly on any other parabola—that is, all parabolas are geometrically similar. write a method 6 method getLatusrectum , getVertexa, getVertexb , getFocusa, getFocusb, getDirectrix
public static void main(String[] args)
{
    Scanner in = new Scanner(System.in);
    double a = in.nextDouble();
    double b = in.nextDouble();
    double c = in.nextDouble();
    Parabola x = new Parabola(a,b,c);
    System.out.println("Latus Rectum = "+"+- "+String.format("%.2f",x.getLatusrectum(c)));
    System.out.println("Vertex: ("+String.format("%.2f",x.getVertexa(a,b))+","+String.format("%.2f",x.getVertexb(a,b,c))+")");
    System.out.println("Focus : ("+String.format("%.2f",x.getFocusa(a,b))+","+String.format("%.2f",x.getFocusb(a,b,c))+")");
    System.out.println("Directrix: y = "+String.format("%.2f",x.getDirectrix(a,b,c)));
}
Awaiting submission
Write a class named Watch with members name, colour and price. The class needs a constructor and get methods for each member.

Test code:

class Q11 {
    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        Watch w = input();

        System.out.println("Watch name: " + w.getName());
        System.out.println("Colour: " + w.getColour());
        System.out.println("Price: " + w.getPrice() + " baht");
    }

    private static Watch input() {
        String name = sc.nextLine();
        String colour = sc.nextLine();
        int price = Integer.parseInt(sc.nextLine());
        return new Watch(name, colour, price);
    }
}
Awaiting submission
Reuse your Watch class from question 1. Add a method named toString that returns the name and the colour.

Test code:


    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        Watch w = input();

        System.out.println(w.toString());
    }

    private static Watch input() {
        String name = sc.nextLine();
        String colour = sc.nextLine();
        int price = Integer.parseInt(sc.nextLine());
        return new Watch(name, colour, price);
    }

Awaiting submission
Reuse your Watch class from question 1. Add a method named getPriceRange that returns a String. If the price is less than 1000 then it is "Budget", if it is greater than 10000 then it is "Executive", else it is "Regular".

Test code:


    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        Watch w = input();

        System.out.print(w.getName() + " is ");
        System.out.println(w.getPriceRange());
    }

    private static Watch input() {
        String name = sc.nextLine();
        String colour = sc.nextLine();
        int price = Integer.parseInt(sc.nextLine());
        return new Watch(name, colour, price);
    }

Awaiting submission
Reuse your Watch class from question 3. Add a method named isBudget that returns true if the watch is less than 1000 baht (0-999).

Test code:


    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        Watch w = input();

        if (w.isBudget()) {
            System.out.println(w.getName() + " is under 1000 baht");
        }
        else {
            System.out.println(w.getName() + " is too expensive");
        }
    }

    private static Watch input() {
        String name = sc.nextLine();
        String colour = sc.nextLine();
        int price = Integer.parseInt(sc.nextLine());
        return new Watch(name, colour, price);
    }

Awaiting submission
Smartwatch is a subclass of Watch. Smartwatch has a String member named operatingSystem (e.g. "WatchOS" or "Android Wear"). Write the Smartwatch class.

Test code:


    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        Smartwatch w = input();

        System.out.println("Watch name: " + w.getName());
        System.out.println("Operating System: " + w.getOperatingSystem());
    }

    private static Smartwatch input() {
        String name = sc.nextLine();
        String colour = sc.nextLine();
        int price = Integer.parseInt(sc.nextLine());
        String operatingSystem = sc.nextLine();
        return new Smartwatch(name, colour, price, operatingSystem);
    }

Awaiting submission
Reuse your Smartwatch class from question 5. Add a method named isAppleWatch that returns true if the operating system is "WatchOS".

Test code:


    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        Smartwatch w = input();

        if (w.isAppleWatch()) {
            System.out.println(w.getName() + " is an Apple Watch");
        }
        else {
            System.out.println("Not an Apple Watch");
        }
    }

    private static Smartwatch input() {
        String name = sc.nextLine();
        String colour = sc.nextLine();
        int price = Integer.parseInt(sc.nextLine());
        String operatingSystem = sc.nextLine();
        return new Smartwatch(name, colour, price, operatingSystem);
    }