Question

(10 points) Consider the output and the main program below. Write class Trumpet such that the program will run and produce th

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN JAVA:

Trumpet.java file:


public class Trumpet {
   String branch ;
   String type ;
   double price ;
   public Trumpet(String branch, String type, double price) {
       super();
       this.branch = branch;
       this.type = type;
       this.price = price;
   }
   public void sale(double percentage) {
       System.out.printf("Sale price: %.1f percent off\n",percentage);
       this.price -= (this.price * percentage / 100);
   }
   public String toString() {
       return "Branch:" + branch + " Type:" + type + " Price=" + price ;
   }
  
}

Code2.java file:


public class Code2 {

   public static void main(String[] args) {
      
       Trumpet t1 = new Trumpet("Bach", "Professional", 4000.00);
       Trumpet t2 = new Trumpet("Getzen", "Intermediate", 1900.00);
       System.out.println(t1.toString());
       System.out.println(t2.toString());
       t1.sale(30);
       System.out.println(t1.toString());
       t2.sale(0);
       System.out.println(t2.toString());

   }

}

OUTPUT:

e Console X <terminated > Code2 [Java Application] C:\Program Files\Java\jdk-13.0.1\bin\javaw.exe (29-May-2020, 2:14:19 am) B

Add a comment
Know the answer?
Add Answer to:
(10 points) Consider the output and the main program below. Write class Trumpet such that the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Predict the output of following Java program class T { int t= 20; T() { t...

    Predict the output of following Java program class T { int t= 20; T() { t = 40 } } class Main { public static void main(String args[]) {    T t1 = new T();    System.out.println(t1.t); } } a.20 b.Garbage value c.40 d.Compiler Error

  • Q19 Consider the following main function: 10 Points public class Main { public static void main(String[]...

    Q19 Consider the following main function: 10 Points public class Main { public static void main(String[] args) { Office office = new Office("5421 Sennott Square"); office.setOccupant("Luis"); office.width 5.0; office.setDepth(4.0); office.closeDoor(); System.out.println( office.toString() ); هه فه Program output (ignore the colors, gradescope's fault): Office information: Location: 5421 Sennott Square Occupant: Luis Area: 20.0 Door: Closed Q19.1 Implement the class Office that makes the program above work and produce the correct output 10 Points public class Office { Enter your answer here

  • 2016 points output of following Java Program? public class Base { public final void show() {...

    2016 points output of following Java Program? public class Base { public final void show() { . System.out.println("Base::show() called"); public class Derived extends Base { public void show() { System.out.println("Derived::show() called"); } e lor rested in order public class Main { ects from and public static void main(String[] args) { Base b = new Derived(); b.show();

  • What output is produced by the following program? public class MysteryNums public static void main(String[] args)...

    What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • What is the output of following program: public class Test{ public static void main(String[] args) {...

    What is the output of following program: public class Test{ public static void main(String[] args) { A a = new A(): a method B(): } } class A{ public A(){ System out println("A's constructor is executed"): } public void method(){ System out printin ("methodA is executed"): } public void methodAB(){ System out printin ("As methodAB is executed"): } } class B extends A { private int num = 0: public B (){ super(): System out printin ("B's constructor is executed"):...

  • Rewrite the following program using the DecimalFormat class so that your output looks like that below....

    Rewrite the following program using the DecimalFormat class so that your output looks like that below. Once again, the example is not calculated as 3/10ths of a percent. Welcome to NIU Investments! Please enter the amount you would like to invest today: 34543.25 Total Investment: $34,543.25 Service Charge: $22.33    ------------- Total Amount Due: $34,565.58 Thank you for your investment! Program: package org.students; import java.util.Scanner; public class NIUInvestments {    //Declaring constant    public static final double SCHARGE=0.0006464;    public...

  • 3.16 LAB: Output range with increment of 10 Write a program whose input is two integers,...

    3.16 LAB: Output range with increment of 10 Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than...

  • This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

    Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...

  • JAVA (implementing a collection class) write a completed program (must include MAIN) and straight to the output based on 4. Based on the implementation of ArrayIntlist or ArrayList, write a class Sor...

    JAVA (implementing a collection class) write a completed program (must include MAIN) and straight to the output based on 4. Based on the implementation of ArrayIntlist or ArrayList, write a class SortedIntList or SortedList that provides most of the same operations but maintains its elements in sorted order. When a new value is added to the sorted list rather than appending it to the end of the list, it is placed in the appropriate index to maintain sorted order of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT