for code given below: 1. write the java statements indicated by the comments 2.
ID: 3822286 • Letter: F
Question
for code given below:
1. write the java statements indicated by the comments
2. compile the source code file ArtShow.java and execute
// ArtShow.java - This program determines if an art show attendee gets a 5% discount
// for preregistering.
// Input: Interactive.
// Output: A statement telling the user if they get a discount or no discount.
import javax.swing.*;
public class ArtShow
{
public static void main(String args[])
{
String registerString;
registerString = JOptionPane.showInputDialog("Did you preregister? Enter Y or N: ");
// Test input here. If Y, call discount(), else call noDiscount().
System.exit(0);
} // End of main() method.
// Write discount method here.
// Write noDiscount method here.
} // End of ArtShow class.
Explanation / Answer
ArtShow.java
import javax.swing.*;
public class ArtShow
{
public static void main(String args[])
{
String registerString;
registerString = JOptionPane.showInputDialog("Did you preregister? Enter Y or N: ");
// Test input here. If Y, call discount(), else call noDiscount().
if(registerString.equals("Y")) {
discount();
}
else{
noDiscount();
}
System.exit(0);
} // End of main() method.
// Write discount method here.
public static void discount() {
System.out.println("an art show attendee gets a 5% discount");
}
// Write noDiscount method here.
public static void noDiscount() {
System.out.println("an art show attendee gets no discount");
}
} // End of ArtShow class.
Output:
an art show attendee gets a 5% discount
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.