Question

In: Computer Science

I am having an issue with the code. The issue I am having removing the part...

I am having an issue with the code. The issue I am having removing the part when it asks the tuter if he would like to do teach more. I want the program to stop when the tuter reaches 40 hours. I believe the issue I am having is coming from the driver.

Source Code:

Person .java File:


public abstract class Person {
private String name;

/**
* Constructor
* @param name
*/
public Person(String name) {
super();
this.name = name;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Name: " + name;
}
  
  
}

**************************************************************************************

Student .java File:


public class Student extends Person {
private int age;
private Tuter tuter;
/**
* @param name
* @param age
* @param tuter
*/
public Student(String name, int age, Tuter tuter) {
super(name);
this.age = age;
this.tuter = tuter;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the tuter
*/
public Tuter getTuter() {
return tuter;
}
/**
* @param tuter the tuter to set
*/
public void setTuter(Tuter tuter) {
this.tuter = tuter;
}
  
private double getDiscountAmount() {
// Calculate discount rate
double discountRate = 0;
if(this.age < 10) {
discountRate = 20;
}
  
return tuter.getTotalDue() * discountRate / 100;
}
  
@Override
public String toString() {
return "Student Name: " + super.getName() + "\nAge: " + age;
}
  
public void printInvoice() {
// Print student info
System.out.println(this.toString());
  
// Print tuter information
System.out.println(tuter.toString());
  
// print the invoices details
System.out.printf("Rate per Hour: $%.2f\n", tuter.getRatePerHour());
System.out.println("Hours of Instruction: " + tuter.getHoursOfInstrction());
  
//Print the discount applied
System.out.printf("Discount applied: $%.2f\n", this.getDiscountAmount());
System.out.printf("Total Due : $%.2f\n", (tuter.getTotalDue() - this.getDiscountAmount()));
}
}

**************************************************************************************

Tuter.java File:


public class Tuter extends Person{
private int hoursOfInstrction;
private double ratePerHour;
private final static int MAX_HOURS = 30;
public Tuter(String name) {
super(name);
this.hoursOfInstrction = 0;
this.ratePerHour = 10.00;
}
/**
* @return the hoursOfInstrction
*/
public int getHoursOfInstrction() {
return hoursOfInstrction;
}

/**
* @param hours the hoursOfInstrction to set
*/
public boolean addHoursOfInstrction(int hours) {
if(this.hoursOfInstrction + hours <= MAX_HOURS) {
this.hoursOfInstrction+= hours;
return true;
}else
return false;
}

  
public double getRatePerHour() {
return ratePerHour;
}


public void setRatePerHour(double ratePerHour) {
this.ratePerHour = ratePerHour;
}
  
  
public double getTotalDue() {
return this.getRatePerHour() * this.getHoursOfInstrction();
}

@Override
public String toString() {
return "Tuter Name: " + super.getName();
}
}

**************************************************************************************

Driver .java File


public class Driver {

public static void main(String[] args) {
//Create a Tuter object
Tuter tuter = new Tuter("Sara");
// Create a Student object and assign the tuter
Student student = new Student("Mai Do", 19, tuter);
int hours;
Scanner scan = new Scanner(System.in);
String choice;
do {
System.out.println("Enter the amount of hours:");
hours = scan.nextInt();
//If tuter can teach more
if(tuter.addHoursOfInstrction(hours)) {
System.out.println("Do you want to teach more? yes/no");
choice = scan.next();
}else
break;
}while(choice.equals("yes"));
  
student.printInvoice();

System.out.println("Another tuter:");

}
}

**************************************************************************************

Solutions

Expert Solution

Solution: HI............ TRY THIS.........


import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author VIDYA
*/

abstract class Person {
private String name;

/**
* Constructor
* @param name
*/
public Person(String name) {
super();
this.name = name;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Name: " + name;
}
  
  
}


class Student extends Person {
private int age;
private Tuter tuter;
/**
* @param name
* @param age
* @param tuter
*/
public Student(String name, int age, Tuter tuter) {
super(name);
this.age = age;
this.tuter = tuter;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the tuter
*/
public Tuter getTuter() {
return tuter;
}
/**
* @param tuter the tuter to set
*/
public void setTuter(Tuter tuter) {
this.tuter = tuter;
}
  
private double getDiscountAmount() {
// Calculate discount rate
double discountRate = 0;
if(this.age < 10) {
discountRate = 20;
}
  
return tuter.getTotalDue() * discountRate / 100;
}
  
@Override
public String toString() {
return "Student Name: " + super.getName() + "\nAge: " + age;
}
  
public void printInvoice() {
// Print student info
System.out.println(this.toString());
  
// Print tuter information
System.out.println(tuter.toString());
  
// print the invoices details
System.out.printf("Rate per Hour: $%.2f\n", tuter.getRatePerHour());
System.out.println("Hours of Instruction: " + tuter.getHoursOfInstrction());
  
//Print the discount applied
System.out.printf("Discount applied: $%.2f\n", this.getDiscountAmount());
System.out.printf("Total Due : $%.2f\n", (tuter.getTotalDue() - this.getDiscountAmount()));
}
}

class Tuter extends Person{
private int hoursOfInstrction;
private double ratePerHour;
final static int MAX_HOURS = 30;
public Tuter(String name) {
super(name);
this.hoursOfInstrction = 0;
this.ratePerHour = 10.00;
}
/**
* @return the hoursOfInstrction
*/
public int getHoursOfInstrction() {
return hoursOfInstrction;
}

/**
* @param hours the hoursOfInstrction to set
*/
public boolean addHoursOfInstrction(int hours) {
if(this.hoursOfInstrction + hours <= MAX_HOURS) {
this.hoursOfInstrction+= hours;
return true;
}else
return false;
}

  
public double getRatePerHour() {
return ratePerHour;
}


public void setRatePerHour(double ratePerHour) {
this.ratePerHour = ratePerHour;
}
  
  
public double getTotalDue() {
return this.getRatePerHour() * this.getHoursOfInstrction();
}

@Override
public String toString() {
return "Tuter Name: " + super.getName();
}
}

public class hours {

public static void main(String[] args) {
//Create a Tuter object
Tuter tuter = new Tuter("Sara");
// Create a Student object and assign the tuter
Student student = new Student("Mai Do", 19, tuter);
int hours;
Scanner scan = new Scanner(System.in);
String choice;
do
{
System.out.println("Enter the amount of hours:");
hours = scan.nextInt();
//If tuter can teach more
if(tuter.addHoursOfInstrction(hours)){
System.out.println("Do you want to teach more? yes/no");
choice = scan.next();
}
else
{
System.out.println("Oooops...!!! Your hours are exceeded");

student.printInvoice();

System.out.println("Another tuter:");

System.exit(0);
}
}while(tuter.addHoursOfInstrction(hours)==false);  

}
}

OUTPUT:


Related Solutions

I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
I am trying to get this code to work but I am having difficulties, would like...
I am trying to get this code to work but I am having difficulties, would like to see if some one can solve it. I tried to start it but im not sure what im doing wrong. please explain if possible package edu.hfcc; /* * Create Java application that will create Fruit class and Bread class * * Fruit class will have 3 data fields name and quantity which you can change. * The third data field price should always...
Hi there, I am having a bit of an issue that I just can't seem to...
Hi there, I am having a bit of an issue that I just can't seem to figure it out. My code is supposed to read from another file and then have an output of a number for each categorie ////////Required Output/////// Movies in Silent Era: 0\n Movies in Pre-Golden Era: 7\n Movies in Golden Era: 581\n Movies in Change Era: 3445\n Movies in Modern Era: 10165\n Movies in New Millennium Era: 15457\n My program is: import java.util.ArrayList; public class MovieReducerEraCount...
I am having trouble with a C++ code that I'm working on. It is a spell...
I am having trouble with a C++ code that I'm working on. It is a spell checker program. It needs to compare two arrays, a dictionary, and an array with misspelled strings that are compared to the strings in the dictionary. the strings that are in the second array that is not in the Dictionary are assumed to be misspelled. All of the strings in the dictionary are lowercase without any extra characters so the strings that are passed into...
I am having an issue with the Java program with a tic tac toe. it isn't...
I am having an issue with the Java program with a tic tac toe. it isn't a game. user puts in the array and it prints out this. 1. Write a method print that will take a two dimensional character array as input, and print the content of the array. This two dimensional character array represents a Tic Tac Toe game. 2. Write a main method that creates several arrays and calls the print method. Below is an example of...
I am having problems getting the second button part of this to work. this is for...
I am having problems getting the second button part of this to work. this is for visual basic using visual studio 2017. Please help. Create an application named You Do It 4 and save it in the VB2017\Chap07 folder. Add two labels and two buttons to the form. Create a class-level variable named strLetters and initialize it to the first 10 uppercase letters of the alphabet (the letters A through J). The first button’s Click event procedure should use the...
I am currently having trouble understanding/finding the errors in this python code. I was told that...
I am currently having trouble understanding/finding the errors in this python code. I was told that there are 5 errors to fix. Code: #!/usr/bin/env python3 choice = "y" while choice == "y": # get monthly investment monthly_investment = float(input(f"Enter monthly investment (0-1000):\t")) if not(monthly_investment > 0 and monthly_investment <= 100): print(f"Entry must be greater than 0 and less than or equal to 1000. " "Please start over.")) #Error 1 extra ")" continue # get yearly interest rate yearly_interest_rate = float(input(f"Enter...
hello, I am having an issue with a question in my highway engineering course. the question...
hello, I am having an issue with a question in my highway engineering course. the question is: An equal tangent sag vertical curve has an initial grade of –2.5%. It is known that the final grade is positive and that the low point is at elevation 82 m and station 1 + 410.000. The PVT of the curve is at elevation 83.5 m and the design speed of the curve is 60 km/h. Determine the station and elevation of the...
Using dev c++ I'm having trouble with classes. I think the part that I am not...
Using dev c++ I'm having trouble with classes. I think the part that I am not understanding is sending data between files and also using bool data. I've been working on this program for a long time with many errors but now I've thrown in my hat to ask for outside help. Here is the homework that has given me so many issues: The [REDACTED] Phone Store needs a program to compute phone charges for some phones sold in the...
I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT