The program calculates the change if the amount of

This preview shows page 10 - 15 out of 18 pages.

The amount inserted by the user. The program calculates the change: If the amount of change to be given is $30 or more then the message: Wait for cheque: value $…” appears. If the amount of change is less than $30 then the message: Change: $… ” appears.. If there is no change to be given then the program gives the message: Thank you. No change. If the amount inserted by the user is too little the following message appears: You have not paid enough! Insert $... More ”. (Sample screen shot below.)
Image of page 10

Subscribe to view the full document.

415.101AC Test January 31 2000 page 11 Complete the main() method so the program behaves as described above. public class Q8 { public static void main(String args[]) { int nItems; // number of items int totalPaid; // total paid by user int perItemC; //cost per item int totalC; //total cost of items int change; //change if there is any int need; //amount needed if user has not paid enough //get user input System.out.print("Number of Items required: "); nItems = Keyboard.readInt(); System.out.print("Cost per Item: $"); perItemC = Keyboard.readInt(); System.out.print("Total paid in: $"); totalPaid = Keyboard.readInt(); totalC = nItems * perItemC; //work out total Cost } }
Image of page 11
415.101AC Test January 31 2000 page 12 Question 9 (5 marks) What is the output from the following program? You can assume that the paint() method is executed ONCE only. import java.awt.*; import java.applet.*; public class Q9 extends Applet{ private String theWord; public void init() { theWord = "with"; String theWord; theWord = "free"; theWord = theWord.concat("hold"); System.out.println(theWord+ " at end of init()"); } public void paint(Graphics g){ System.out.println(theWord+ " in paint()"); } }
Image of page 12

Subscribe to view the full document.

415.101AC Test January 31 2000 page 13 Question 10 (13 marks) The applet below uses a class called MyCircle to draw a circle on the screen. The applet also has four buttons which have the following effect on the circle: bigger : increases the radius of the circle by 10 pixels smaller : decreases the radius of the circle by 10 pixels fill : causes the circle to be drawn filled in rather than in outline don't fill : causes the circle to be drawn in outline When the applet first runs, the circle should be drawn in outline, rather than filled. If the user clicks the bigger or smaller buttons, the size of the circle should change. In the following picture, the user has clicked on the smaller button twice: If the user clicks on the fill button, the circle should be drawn filled in, and when the user clicks on the don't fill button, the circle should be drawn in outline. In the screen shots on the following page, the user has clicked on the fill button, followed by a click on the don't fill button:
Image of page 13
415.101AC Test January 31 2000 page 14 Below is source code for the Applet class which uses the MyCircle class: import java.awt.*; import java.awt.event.*;
Image of page 14

Subscribe to view the full document.

Image of page 15
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • English-language films, Following, Denys Cowan

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern